Announcement Announcement Module
Collapse
No announcement yet.
Showing global errors with velocity and binding Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Showing global errors with velocity and binding

    Hi,

    I have this snippet of VTL in one of my templates, and it works fine, it shows the field-specific errors no problem.

    Name: #springBind("userIdentification.username")
    <input type="text" name="$!{status.expression}" value="$!{status.value}" />
    #foreach($error in $status.errorMessages) <b> $error </b> <br> #end

    What I can't work out how to do is display the global errors?

    I set an error in my controller onSubmit(4 args) like so:

    errors.reject("login.invalid", "Your entered username and/or password is incorrect.");
    return showForm(request, response, errors);

    But I just cannot work out how to get the error message out in my vm.

    Regards,

    Eliot

  • #2
    use
    Code:
    #springBind&#40;"userIdentification.*"&#41;
    HTH

    Comment


    • #3
      Just tried that out, and it's working better now - thank you.

      I'm now stuck on how to get only the global error messages out (by that I mean the error messages that aren't specific to a field).

      Here's my updated snippet of VTL:

      ## Retrieve and display the global error messages.
      #springBind("userIdentification.*")

      ## Shows BOTH global (wanted) and field (not wanted) error messages.
      #foreach($error in $status.errorMessages) <b> $error </b> <br> #end

      <form action="" method="POST">
      ## Retrieve bound data for the username field.
      Name: #springBind("userIdentification.username")
      <input type="text" name="$!{status.expression}" value="$!{status.value}" />
      #foreach($error in $status.errorMessages) <b> $error </b> <br> #end
      <br>

      Do you know how can I retrieve just the global messages? Also, where can I find the VTL for the springBind macro?

      Thanks and kind regards,
      Eliot

      Comment


      • #4
        The VTL to get back just global messages:

        ## Retrieve and display the global error messages.
        #springBind("userIdentification")
        #foreach($error in $status.errorMessages) <b> $error </b> <br> #end

        In other words, just needed to remove the ".*" from the end of my command's name in the macro call (userIdentification).

        Also, the macro file name is spring.vm and can be found in the spring jar or if you want to see the latest spring.vm in CVS:

        http://cvs.sourceforge.net/viewcvs.p...vm?view=markup

        Comment


        • #5
          Originally posted by irbouho View Post
          use
          Code:
          #springBind("userIdentification.*")
          HTH
          THANK YOU! I spent quite some time trying to find that out (newbie to Velocity *and* Spring MVC, did not grasp the path idea until I saw your code)

          Comment

          Working...
          X