Announcement Announcement Module
Collapse
No announcement yet.
Problem with spring:message and parameters Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with spring:message and parameters

    Hi to all,

    I'm trying to iterate through the errors collection in a jsp and display all the messages, some of wich may include parameters. Now i'm trying to figure out how to do this with the spring:message tag because it does not seem to resolve those parameters. Ie: If I have this code in a validator:

    Code:
    errors.reject("form.myError",new Object[]{reo.getRevision()},"");
    with a key in message.properties like : form.myError= Revision {0} is invalid. When the jsp executes with the following:

    Code:
    <c&#58;forEach var="error" items="$&#123;errors.allErrors&#125;">
         <spring&#58;message code="$&#123;error.code&#125;" />
    </c&#58;forEach>
    it prints: Revision {0} is invalid.

    How can we resolve the the message *and* the parameters in that loop? Any ideas???

    Uze

  • #2
    Well, this code seems to make it but is there a shorter way? Something like <c:out key="${error.messageWithParametersReplaced}"/>?

    Code:
    <spring&#58;hasBindErrors name="model">
    	<c&#58;forEach var="error" items="$&#123;errors.allErrors&#125;">
    		<fmt&#58;message key="$&#123;error.code&#125;">
    			<c&#58;forEach var="arg" items="$&#123;error.arguments&#125;">
    				<fmt&#58;param value="$&#123;arg&#125;"/>
    			</c&#58;forEach>
    		 </fmt&#58;message>
    		<br>
    	</c&#58;forEach>
    </spring&#58;hasBindErrors>
    Anyway that works, so i'll live with it.

    Uze

    Comment


    • #3
      this works for me:

      Code:
           
           <spring&#58;bind path="command">
              <c&#58;forEach var="error" items="$&#123;status.errorMessages&#125;">
              <p><font color="red"><c&#58;out value="$&#123;error&#125;"/></font><p>
              </c&#58;forEach >
           </spring&#58;bind>
      rgds
      kev

      Comment


      • #4
        This is better

        Inside the
        spring:hasBindErrors and c:forEach tags
        use this

        <spring:message code="${error.code}" arguments="${error.arguments}" text="Please correct the errors before continuing."/>

        instead of

        <fmt:message key="${error.code}">
        <c:forEach var="arg" items="${error.arguments}">
        <fmtaram value="${arg}"/>
        </c:forEach>
        </fmt:message>

        Comment

        Working...
        X