Struts error taglib ver. 1.2

    Custom JSP taglib lets you deal with error messages in your Struts applications. Just a some basic: In Struts framework on submission of a form, each form field value is copied to the corresponding attribute of the appropriate ActionForm bean. When composing the response, each form field is initialized with the value of the corresponding attribute from the ActionForm bean. ActionForm subclasses can optionally implement a validate() method to perform simple validation (e.g. check for mandatory fields, types etc.) on the form data before control is transferred to the Action object. If any validation errors are returned by this method, request processing stops and the response is generated using the input page. Error messages can be included in the response using the Struts <html:errors> tag.

This taglib offers a useful alternative to the standard <html:errors> tag. For example, in your ActionForm you can have some like this:
 


 errors.add(
   "error_property", new ActionError("your error message"));

On the top of your jsp page you can have some like this:
 


<%@ taglib uri="taglib.tld" prefix="s" %>

<s:forEachError>
 <br><%=errorProperty%> : <%=errorMessage%>
</s:forEachError>

here we will print all the messages. Tag uses two nested variables (type is java.lang.String). errorProperty keeps a value for the current property and errorMessage keeps a value for the current message.

Tag getErrorMessage lets you request (print) error message. Tag errorsExist lets you test the presense for error. Tag popupError lets you produce a JavaScript popup window with error message.

Tags are:

forEachError

Body tag iterates over existing errors. Parameters are: none

getErrorMessage

Tag prints (saves in the page scope variable) an error message. Tag prints nothing if error message does not exist. Parameters are:

1) property Optional parameter. Describes a name for the property. Without this parameter tag uses the first error message.
2) id Optional parameter. Describes a name for the page scope variable (type is java.lang.String) for data. Without this parameter tag just prints data.

errorsExist

Body tag executes own body if error exists. Parameters are:

1) property Optional parameter. Describes a name for the property.

popupError

Tag produces a popup window with error message. Tag does nothing if error message does not exist. Parameters are:

1) property Optional parameter. Describes a name for the property. Without this parameter tag uses the first error message.
2) back Optional parameter. Possible values are true or false. If this value is true then closing popup will return control to the previous page. Default value is true.
3) stop Optional parameter. Possible values are true or false. If this value is true then popup window with error message will stop the rendering for your page. Default value is true.

for downloading:

Library: strutserrortag.jar    Description: taglib.tld

© Coldbeans      Comments?

See also Coldtags suite - the largest collection of custom JSP tags.