Alert
The Alert
component in webforJ provides contextual feedback messages for users. It's a versatile way to display important information, warnings, or notifications in your app.
Alerts help draw attention to key information without disrupting the user's workflow. They're perfect for system messages, form validation feedback, or status updates that need to be clearly visible but not intrusive.
Here's an example of an alert component:
Show Code
- Java
Dismissing alerts
If you’d like to give users the option to dismiss the Alert
, you can make it closable by calling the setClosable()
method.
Alert alert = new Alert("Heads up! This alert can be dismissed.");
closableAlert.setClosable(true);
Alerts often do more than display messages—they can trigger follow-up actions when dismissed. Use the AlertCloseEvent
to handle these cases and respond when the user dismisses the Alert
.
Show Code
- Java
Closing the alert only hides it—it doesn’t destroy the component, so you can reuse it later if needed.
Styling
Themes
The Alert
component supports multiple themes to visually distinguish different types of messages—such as success, error, warning, or info. These themes can be applied using the setTheme()
method or directly in the constructor.
Show Code
- Java
Expanses
The expanse defines the visual size of the Alert
component. You can set it using the setExpanse()
method or pass it directly to the constructor. The available options come from the Expanse enum: XSMALL
, SMALL
, MEDIUM
, LARGE
, and XLARGE
.
Show Code
- Java
Shadow Parts
These are the various parts of the shadow DOM for the component, which will be required when styling via CSS is desired.
Reflected Attributes
The reflected attributes of a component will be shown as attributes in the rendered HTML element for the component in the DOM. This means that styling can be applied using these attributes.
Dependencies
This component relies on the following components - see the related article for more detailed styling information: