Action saveMessages and getResources into struts

Action saveMessages and getResources into struts

Previous Home Next

 

saveMessagesand getResources method helper methods of Action into struts framework.ActionMessages to display dynamic i18n-enabled messages. Working with ActionMessages and ActionErrors is nearly identical but only difference is that the <html:errors> tag forced you to place HTML in the message resource file.This is not good.

 
In <html:messages> tag, We can sets up a loop where you may easily stick in the HTML you want.
This forces <html:messages> to get the messages from Globals.MESSAGE_KEY in request scope. (if messages="true" is set), if any messages are required.

<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>

<html:messages id="msg" message="true">
<bean:write name="msg"/>
<br></html:messages>

saveMessages :-   This method save the specified messages keys into the appropriate request or session attribute for use by the <html:messages> tag.

Syntex of this method :-

protected  void saveMessages(HttpServletRequest request, ActionMessages messages) 
protected  void saveMessages(HttpSession session, ActionMessages messages) 
        
getResources :-This method is used to get number of messages resources for that locale.

Syntex of this method :-

protected  MessageResources getResources(HttpServletRequest request) :-This method
will return the default message resources for the current locale.

protected  MessageResources getResources(HttpServletRequest request, String key):- This method will return the specified message resources for the current locale.


Previous Home Next