Results 1 to 4 of 4

Thread: Problem with spring:message and parameters

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Location
    Montreal, Canada
    Posts
    35

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Montreal, Canada
    Posts
    35

    Default

    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

  3. #3
    Join Date
    Nov 2004
    Posts
    6

    Default

    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

  4. #4
    Join Date
    Nov 2006
    Posts
    1

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •