Formatting Issue in HTML messages from ResourceBundle using or in Struts2

后端 未结 1 2041
说谎
说谎 2021-01-29 01:26

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.<

相关标签:
1条回答
  • 2021-01-29 01:53

    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:

    <ul class="actionMessage"><li><span>
    
        <font color="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:if test="actionMessages!=null && actionMessages.size > 0">
        <div class="actionmessage">
            <s:iterator value="actionMessages" >
                <span>
                    <s:property escapeHtml = "false" />
                </span>
                <br/>
            </s:iterator>
        </div>
    </s:if>
    

    result:

    <div class="actionmessage"><span>
    
        <font color="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:include value="/WEB-INF/content/fragments/messages.jsp" />
    
    0 讨论(0)
提交回复
热议问题