Announcement Announcement Module
Collapse
No announcement yet.
Spring has bugs with displaying Errors arguments? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring has bugs with displaying Errors arguments?

    The arguments for global errors and the fall-back message for field specific errors do not work. The former has been raised and not answered here:

    http://forum.springsource.org/showth...ments-resolved

    The JARs are dated 2008 so probably version 2.5.

    Are these known bugs / fixed in a more recent version?

    Thanks!

  • #2
    That isn't a bug that is wrong usage... If you don't pass in the variables to the message tag the message tag doesn't know what to show... You shouldn't use the message tag (or that way at all) to show your error messages. Resolving the message is already handled by spring for yuo. If you persist on using it like this, pass in the arguments to the message tag also...

    Comment


    • #3
      Originally posted by Marten Deinum View Post
      That isn't a bug that is wrong usage... If you don't pass in the variables to the message tag the message tag doesn't know what to show... You shouldn't use the message tag (or that way at all) to show your error messages. Resolving the message is already handled by spring for yuo. If you persist on using it like this, pass in the arguments to the message tag also...
      I am passing the variables to the message tag, an Object array of parameters as per the Errors class API. By arguments I mean the 'errorArgs' (see below). This method, the field-specific one, works:

      rejectValue(String field, String errorCode, Object[] errorArgs, String defaultMessage)

      This one, the global one:

      reject(String errorCode, Object[] errorArgs, String defaultMessage)

      does not, I get the message displayed but the errorArgs are not filled in, as if I have not defined them (I have defined them).

      reject(String errorCode) works, there is nothing wrong with my config.

      Comment


      • #4
        Again if you follow the sample provided in the thread you pointed to and use the same (WRONG) spring:message tag to display your messages you are NOT passing in the arguments to the message tag, regardless of what you put in your reject(Value)... If you use a different mechanism post the full code instead of a snippet and referencing another thread (which might or might not be related).

        Comment


        • #5
          The display mechanism is jstl:

          Code:
          <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
          Code:
          <spring:hasBindErrors name="nameOfCommandObjectHere">
          <li class="inputField">&nbsp;</li>
          <c:forEach items="${errors.globalErrors}" var="error">
          		<li class="inputField"><p class="errorMessage"><fmt:message key="${error.code}" /></p></li>
          	</c:forEach>
          </spring:hasBindErrors>
          Thanks

          Comment


          • #6
            As I already stated you are only issueing the code, you are NOT passing in the arguments to the message tag... So how should it know the parameters... I suggest taking a look at the docs regarding the message tag (next to that you should use the spring:message tag and not the fmt one).

            Or simply pass in the error as the message which saves you a lot of work..

            Code:
            <spring:hasBindErrors name="nameOfCommandObjectHere">
            <li class="inputField">&nbsp;</li>
            <c:forEach items="${errors.globalErrors}" var="error">
            		<li class="inputField"><p class="errorMessage"><spring:message message="${error}" /></p></li>
            	</c:forEach>
            </spring:hasBindErrors>
            or the hard way..


            Code:
            <spring:hasBindErrors name="nameOfCommandObjectHere">
            <li class="inputField">&nbsp;</li>
            <c:forEach items="${errors.globalErrors}" var="error">
            		<li class="inputField"><p class="errorMessage"><spring:message code="${error.code}" arguments="${error.arguments}" /></p></li>
            	</c:forEach>
            </spring:hasBindErrors>
            Last edited by Marten Deinum; Jun 30th, 2011, 12:06 PM. Reason: added code.

            Comment

            Working...
            X