Class ErrorLayout


public class ErrorLayout extends PageLayout<ErrorLayout>
A layout for error pages with status code, message, and recovery actions.

ErrorLayout provides a centered, user-friendly structure for displaying error states such as 404 Not Found, 403 Forbidden, 500 Server Error, or any application-specific error conditions that require user attention and potential recovery actions.

Structure:

 ┌──────────────────────────────────────┐
 │                                      │
 │              ┌─────┐                 │
 │              │ 404 │                 │  (Status Code)
 │              └─────┘                 │
 │                                      │
 │          Page Not Found              │  (Title)
 │                                      │
 │   The page you're looking for        │
 │   doesn't exist or has been moved.   │  (Message)
 │                                      │
 │     [ Go Home ]  [ Go Back ]         │  (Actions)
 │                                      │
 └──────────────────────────────────────┘
 

Features:

  • Large status code display
  • Error title and detailed message
  • Recovery action buttons
  • Optional icon/illustration
  • Configurable styling for different error types

Usage:


 // Basic 404 error
 ErrorLayout error = new ErrorLayout();
 error.status(404)
      .title("Page Not Found")
      .message("The page you're looking for doesn't exist.")
      .action(goHomeBtn);

 // With multiple actions
 ErrorLayout error = new ErrorLayout();
 error.status(403)
      .title("Access Denied")
      .message("You don't have permission to view this page.")
      .actions(loginBtn, requestAccessBtn);

 // With custom icon
 ErrorLayout error = new ErrorLayout();
 error.icon(serverErrorIcon)
      .status(500)
      .title("Server Error")
      .message("Something went wrong on our end.")
      .action(retryBtn);

 // Full viewport
 error.fillViewport();
 
Since:
2025
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • ErrorLayout

      public ErrorLayout()
      Constructs an ErrorLayout with default configuration.
  • Method Details

    • initialize

      protected void initialize()
      Builds the element tree for the layout.
      Overrides:
      initialize in class StyledElement<ErrorLayout>
    • status

      public ErrorLayout status(int statusCode)
      Sets the error status code.
      Parameters:
      statusCode - the HTTP status code (e.g., 404, 500)
      Returns:
      this ErrorLayout for method chaining
    • status

      public ErrorLayout status(String statusCode)
      Sets the error status code as text.
      Parameters:
      statusCode - the status code text (e.g., "404", "Error")
      Returns:
      this ErrorLayout for method chaining
    • status

      public ErrorLayout status(Element<?> statusElement)
      Sets the error status as an element.
      Parameters:
      statusElement - the status element
      Returns:
      this ErrorLayout for method chaining
    • icon

      public ErrorLayout icon(Element<?> icon)
      Sets an icon or illustration.
      Parameters:
      icon - the icon element
      Returns:
      this ErrorLayout for method chaining
    • title

      public ErrorLayout title(String title)
      Sets the error title.
      Parameters:
      title - the title text
      Returns:
      this ErrorLayout for method chaining
    • title

      public ErrorLayout title(Element<?> title)
      Sets the error title as an element.
      Parameters:
      title - the title element
      Returns:
      this ErrorLayout for method chaining
    • message

      public ErrorLayout message(String message)
      Sets the error message.
      Parameters:
      message - the message text
      Returns:
      this ErrorLayout for method chaining
    • message

      public ErrorLayout message(Element<?> message)
      Sets the error message as an element.
      Parameters:
      message - the message element
      Returns:
      this ErrorLayout for method chaining
    • action

      public ErrorLayout action(Element<?> action)
      Sets a single action button.
      Parameters:
      action - the action button element
      Returns:
      this ErrorLayout for method chaining
    • actions

      public ErrorLayout actions(Element<?>... actions)
      Sets multiple action buttons.
      Parameters:
      actions - the action button elements
      Returns:
      this ErrorLayout for method chaining
    • setStatusColor

      public ErrorLayout setStatusColor(String color)
      Sets the status code color.
      Parameters:
      color - the text color
      Returns:
      this ErrorLayout for method chaining
    • setStatusSize

      public ErrorLayout setStatusSize(String size)
      Sets the status code font size.
      Parameters:
      size - the font size (e.g., "6rem", "96px")
      Returns:
      this ErrorLayout for method chaining
    • setTitleColor

      public ErrorLayout setTitleColor(String color)
      Sets the title color.
      Parameters:
      color - the text color
      Returns:
      this ErrorLayout for method chaining
    • setMessageColor

      public ErrorLayout setMessageColor(String color)
      Sets the message color.
      Parameters:
      color - the text color
      Returns:
      this ErrorLayout for method chaining
    • setMaxWidth

      public ErrorLayout setMaxWidth(int maxWidth)
      Sets the maximum width of the content container.
      Overrides:
      setMaxWidth in class StyledElement<ErrorLayout>
      Parameters:
      maxWidth - the max width in pixels
      Returns:
      this ErrorLayout for method chaining
    • setMaxWidth

      public ErrorLayout setMaxWidth(String maxWidth)
      Sets the maximum width of the content container.
      Overrides:
      setMaxWidth in class StyledElement<ErrorLayout>
      Parameters:
      maxWidth - the max width value (e.g., "500px", "50%")
      Returns:
      this ErrorLayout for method chaining
    • setContentPadding

      public ErrorLayout setContentPadding(int padding)
      Sets padding for the content container.
      Parameters:
      padding - the padding in pixels
      Returns:
      this ErrorLayout for method chaining
    • setContentPadding

      public ErrorLayout setContentPadding(String padding)
      Sets padding for the content container.
      Parameters:
      padding - the padding value (e.g., "32px", "2rem")
      Returns:
      this ErrorLayout for method chaining
    • setActionsGap

      public ErrorLayout setActionsGap(int gap)
      Sets the gap between action buttons.
      Parameters:
      gap - the gap in pixels
      Returns:
      this ErrorLayout for method chaining
    • setActionsGap

      public ErrorLayout setActionsGap(String gap)
      Sets the gap between action buttons.
      Parameters:
      gap - the gap value (e.g., "12px", "1rem")
      Returns:
      this ErrorLayout for method chaining
    • getContainer

      public Div getContainer()
      Returns the container for advanced customization.
      Returns:
      the container div
    • getIconArea

      public Div getIconArea()
      Returns the icon area for advanced customization.
      Returns:
      the icon area div
    • getStatusArea

      public Div getStatusArea()
      Returns the status area for advanced customization.
      Returns:
      the status area div
    • getTitleArea

      public Div getTitleArea()
      Returns the title area for advanced customization.
      Returns:
      the title area div
    • getMessageArea

      public Div getMessageArea()
      Returns the message area for advanced customization.
      Returns:
      the message area div
    • getActionsArea

      public Div getActionsArea()
      Returns the actions area for advanced customization.
      Returns:
      the actions area div
    • error404

      public ErrorLayout error404()
      Configures the layout for a 404 Not Found error.

      Sets the status code, title, and message with appropriate styling.

      Returns:
      this ErrorLayout for method chaining
    • error403

      public ErrorLayout error403()
      Configures the layout for a 403 Forbidden error.

      Sets the status code, title, and message with appropriate styling.

      Returns:
      this ErrorLayout for method chaining
    • error500

      public ErrorLayout error500()
      Configures the layout for a 500 Internal Server Error.

      Sets the status code, title, and message with appropriate styling.

      Returns:
      this ErrorLayout for method chaining
    • error503

      public ErrorLayout error503()
      Configures the layout for a 503 Service Unavailable error.

      Sets the status code, title, and message with appropriate styling.

      Returns:
      this ErrorLayout for method chaining
    • dangerStyle

      public ErrorLayout dangerStyle()
      Applies a danger/error color scheme (red tones).
      Returns:
      this ErrorLayout for method chaining
    • warningStyle

      public ErrorLayout warningStyle()
      Applies a warning color scheme (orange tones).
      Returns:
      this ErrorLayout for method chaining
    • mutedStyle

      public ErrorLayout mutedStyle()
      Applies a muted/neutral color scheme (gray tones).
      Returns:
      this ErrorLayout for method chaining