Message Renderer
In ReqEase, rendering messages to provide feedback to users is a fundamental aspect of handling responses and ensuring a smooth user experience. Messages can take various forms, such as success messages, error messages, or informational messages, and they can be displayed within your web application in different ways, like in a form, toast notifications, or attached to input fields. To facilitate this, ReqEase provides message rendering capabilities through message handlers and renderers.
DefaultMessage and DefaultMessageRenderer
The core of message rendering in ReqEase revolves around the DefaultMessage
class and its corresponding renderer interface, DefaultMessageRenderer
. This foundation allows for consistent message handling across different message types, such as form messages, input messages, and toast messages. Here's an overview:
DefaultMessage
: An abstract class that serves as the base for all message types. It takes generic parametersMessageData
(the message's data structure) andMessageRenderer
(the associated renderer).messageData
: An array of message data to render.messageRenderer
: The renderer responsible for displaying the messages.show()
: An abstract method to show the messages.destroy()
: An abstract method to destroy or remove the messages.
DefaultMessageRenderer
: An interface specifying methods required for rendering messages. It includes:buildMessage
: Builds and returns the HTML representation of a single message.renderMessages
: Renders multiple messages.removeMessages
: Removes displayed messages.
FormMessage Example
An example of a concrete message type is FormMessage
. It extends DefaultMessage
and has an associated FormMessageRenderer
. Here's how it works:
Default Form Message Renderer
defaultFormMessageRenderer
is the default renderer for form messages in ReqEase. It builds form messages based on the provided message data. Here's an example of its configuration:
InputMessage and ToastMessage
In addition to FormMessage
, ReqEase provides two more message types: InputMessage
and ToastMessage
. These types follow the same pattern as FormMessage
and are used for different display scenarios.
InputMessage
: Used for attaching messages to input fields and interacting with user input.ToastMessage
: Displays messages as toast notifications in the application.
Customizing Message Rendering
ReqEase allows developers to customize message rendering by implementing their own message handlers and renderers. By creating custom message types and corresponding renderers, you can tailor the message presentation to your application's needs. These customizations are especially useful when integrating ReqEase with different frontend frameworks or libraries.
In ReqEase, message rendering is a versatile and extensible feature that enhances user communication and feedback within your web application.
Last updated