Skip to content Skip to sidebar Skip to footer

Formatting Issue In Html Messages From Resourcebundle Using Or In Struts2

I have a properties file (resource bundle). I am trying to show errors in one of the jsp by loading them from properties file. I have an entry as below in my properties file. erro

Solution 1:

The <s:actionerror/> and <s:actionmessage/> tags will encapsulate your actionerrors and actionmessages in <ul><li><span>yourmessage</span></li></ul>.

This will make your message starting with a circle dot (because it is inside an <li>) and the other nested <li> with the circle outline (as defined by HTML for second-level <li>).

This:

<s:actionmessage />

will generate:

<ulclass="actionMessage"><li><span><fontcolor="red">The password you have entered does not 
    meet password strength requirements.  Please select a new password that conforms 
    to the following standards:<UL><LI>Minimum length of 8 characters</LI><LI>Maximum length of 18 characters</LI><LI>At least one upper-case character</LI><LI>At least one lower-case character</LI><LI>At least one non-alphabetic character</LI><LI>Does not contain 3 or more consecutive repeating characters (e.g. AAA)</LI><LI>Does not contain the User ID</LI><LI>Does not contain common dictionary words 
    more than 4 characters long</LI><LI>New Password should not be the same as 
    previous password</LI></UL></font></span></li></ul>

To generate the output you want, you can write your own .ftl, or more easily avoid using the <s:actionerror/> / <s:actionmessage> tags, and do the loop by yourself:

<s:iftest="actionMessages!=null && actionMessages.size > 0"><divclass="actionmessage"><s:iteratorvalue="actionMessages" ><span><s:propertyescapeHtml = "false" /></span><br/></s:iterator></div></s:if>

result:

<divclass="actionmessage"><span><fontcolor="red">The password you have entered does not 
    meet password strength requirements.  Please select a new password that conforms 
    to the following standards:<UL><LI>Minimum length of 8 characters</LI><LI>Maximum length of 18 characters</LI><LI>At least one upper-case character</LI><LI>At least one lower-case character</LI><LI>At least one non-alphabetic character</LI><LI>Does not contain 3 or more consecutive repeating characters (e.g. AAA)</LI><LI>Does not contain the User ID</LI><LI>Does not contain common dictionary words 
    more than 4 characters long</LI><LI>New Password should not be the same as 
    previous password</LI></UL></font></span><br/></div>

You can do the loop for actionMessages, actionErrors and eventually fieldErrors and put them in a messages.jsp snippet, so you can use it in every page (without rewriting it every time) with something like:

<s:includevalue="/WEB-INF/content/fragments/messages.jsp" />

Post a Comment for "Formatting Issue In Html Messages From Resourcebundle Using Or In Struts2"