Announcement Announcement Module
Collapse
No announcement yet.
[Validation] Problem outputting arguments from messageSource Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Validation] Problem outputting arguments from messageSource

    Hi i am new to the spring MVC and have a question i made a validation class that does the following if a error occurs:

    PHP Code:
    errors.rejectValue("selectionA""error.proto.wrong-select", new Object[] {"Sentinel"}, null); 
    In my messages.properties i added the following line

    error.proto.wrong-select=Please select a {0}

    If i display the error in two ways, first a global sumup on top of the page of al the errors, and i display the error above the formfield

    The error above the error field is as follows:

    PHP Code:
    <spring:bind path="${path}">
        <
    c:if test="${status.error}">
            <
    span class="error">
                <
    c:forEach items="${status.errorMessages}var="error">
                    <
    c:out value="${error}"/>
                </
    c:forEach>
            </
    span><br />
        </
    c:if>
        <
    label for="<c:out value="${status.expression}"/>">${name}: </label>
        <
    form:select onchange="${onchange}path="${path}">
            <
    c:choose>
                <
    c:when test="${empty list}">
                    <
    form:option value="-1" label="--First select a ${depended}--" />
                </
    c:when>
                <
    c:otherwise>
                    <
    form:option value="-1" label="--Please Select--" />
                    <
    form:options items="${list}/>
                </
    c:otherwise>
            </
    c:choose>
        </
    form:select><br />
    </
    spring:bind
    And the global errors:

    PHP Code:
    <spring:hasBindErrors name="${name}">
    <
    p>There were <c:out value="${errors.errorCount}"/> error(sfound:</p>
        <
    ul>
            <
    c:forEach var="errMsgObj" items="${errors.allErrors}>
                <
    li>
                    <
    spring:message code="${errMsgObj.code}text="${errMsgObj.defaultMessage}/>
                </
    li>
            </
    c:forEach>
        </
    ul
    </
    spring:hasBindErrors

    The problem is that the error in global errors doesn't show the object set with the reject.
    so it displays :
    Please select a {0}

    and the error above the field shows:
    Please select a Sentinel

    what am i doing wrong? Hope somebody can help me.

    Regards,

    Olaf

  • #2
    *bump*

    Anyone an idea how to fix this?

    Comment


    • #3
      for future references, maybe somebody with the same problems, i fixed the problem, it was the following:

      PHP Code:
      <spring:hasBindErrors name="${name}">
          <
      fieldset id="errorBox">
              <
      legend><img src="images/caution-e.gif"Errors</legend>    
              <
      span>There were <c:out value="${errors.errorCount}"/> error(sfound:</span>
                  <
      ul>
                      <
      c:forEach var="errMsgObj" items="${errors.allErrors}>
                          <
      li>
                              <
      spring:message arguments="${errMsgObj.arguments}code="${errMsgObj.code}text="${errMsgObj.defaultMessage}/>
                          </
      li>
                      </
      c:forEach>
                  </
      ul>     
          </
      fieldset>
      </
      spring:hasBindErrors
      I needed to pass the arguments to the spring:message tag, otherwise they where not recognized.

      Comment

      Working...
      X