Announcement Announcement Module
No announcement yet.
problem with <spring:hasBindErrors... tag Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem with <spring:hasBindErrors... tag

    I am having a problem getting output from the hasBindErrors tag.
    I have set up my validator class and all is well there. It idents the command object I am feeding it and pulls the data from it okay (which is tag binded from the same form controller).
    And I have my LoginCommand object (which is custom extended from HashMap).

    I have created some validation like so:

    LoginCommand loginCommand = ( LoginCommand ) obj;
    String strUserId = loginCommand.getUserId();

    ValidationUtils.rejectIfEmpty( errors, "userId", "error.code",
    "No entry found within the UserId field." );

    if( !strUserId.equalsIgnoreCase( "admin" ) )
    errors.rejectValue( "userId", "userId.Unknown", "User Id " + strUserId
    + " is invalid and unknown to the system." );

    I have put some fast debug output out with:

    System.out.println( ">>>> 1: " + errors.getAllErrors() );
    System.out.println( ">>>> 2: " + errors.getObjectName());

    This shows me the errors are being set-up correctly and do exist.
    And my JSP code is like so:
    <spring:hasBindErrors name="model.userId">
    <c:out value="${errors}"/>
    <c:out value="${errors.errorCount}"/>
    <c:out value="${status.errorMessage}"/>
    <c:out value="${status.errorMessages}"/>

    And I get nothing back.

    I have also an entry in my file like so:
    userId.Unknown=Username not valid, try 'guest'

    In my form controller I have a showForm which returns:

    return new ModelAndView( getFormView(), "model", mapModel );

    Could someone explain to me my flaw?

  • #2
    This page[1] helped someone who had a similar problem recently. Search on "Writing the JSP" and look at the spring:hasBindErrors example right below it.




    • #3
      still not working

      Thanks for that link.

      What it does not say there is how the core tag binding picks up the errors, by what ident name if you changed things around? How does that part of it work exactly?

      In my showForm method I have now managed to output the errors with some debug system.outs. So, they do exist somewhere in the system.

      System.out.println( "E1: " + errors.getAllErrors() );
      System.out.println( "E2: " + errors.getObjectName() );
      System.out.println( "E3: " + errors.getModel() );

      But its still not displaying them from the JSP as I am not sure how to get the error information out from the core tag bindings. I think the name of the mapping I am trying to bind is wrong.

      Any ideas?


      • #4
        getting closer to the problem

        I have now managed to output the value for status.error in the JSP.
        And this is returning false all the time, yet there seems to be errors setup correctly in the model.

        So, for some reason status.error is not being set to true.


        • #5

          Okay the reason the errors did not appear is that in the showForm method which is inherited from the AbstractFormController class they are added with the method call of:

          map.putAll( errors );

          However I overloaded my showForm and thus my custom model returned to Springs MVC did not contain the errors. And the JSP could not find them to display them (as they were never added to the model).

          The reason I had overridden that method was due to the fact I have dynamic links/buttons being added to the form at runtime. And thus needed to add them on the initial form display.

          By moving that code to the formBackingObject (where it really should have been) there was no longer a need to override the showForm method. And the errors were added correctly.

          Problem solved.