Announcement Announcement Module
Collapse
No announcement yet.
Displaying Errors/Messages from MessageContext in JSP/JSTL Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Displaying Errors/Messages from MessageContext in JSP/JSTL

    Hy,

    I have a Webflow with a model that gets validated after submit.
    The validation is correctly called and I add an errormessage to the MessageContext.
    When i put the MessageContext in the requestScope i can display all errors (${messageContext.allMessages} ).

    But I couldn't find out how to display the errormessages in the form with the Spring form:errors Tag.. the result is always empty.

    jsp code looks like this :
    Code:
    <form:form modelAttribute="registerForm" action="${pageContext.request.scheme }://${pageContext.request.serverName }:${pageContext.request.serverPort }${flowExecutionUrl}">
    <form:errors path="*" ></form:errors>
    <spring:bind path="firstName">
    <input name="${status.expression}" type="text" value="${status.value}" >
    </spring:bind>
    
    								<input type="submit" name="_eventId_submitRegistration" value="Submit" />
    </form:form>
    and my validate Function:
    Code:
      public boolean validateRegister(MessageContext context) {
        MessageResolver msg = new MessageBuilder().error().source("registerForm.firstName").code("register.Field.missing").build();
        context.addMessage(msg);
        context.addMessage(new MessageBuilder().error().source("firstName").code("register.Field.missing").build());
     }

  • #2
    Same question, and I assume that there has to be some binding that is done to Spring Errors, and that this binding happens automatically for 'valicate${state-id} methods.

    Comment


    • #3
      You might want to review the web flow sample booking-mvc which shows use of the errors tag.

      Keith

      Comment


      • #4
        Hi, Keith. I've got exactly the same problem as icewolf. I handle all my business exceptions and validation errors via MessageContext, e.g.

        Code:
        		new MessageBuilder().error().source("exists")
        				.code("album.create.error.exists").build());
        When I try to display errors with form:errors tag i can see nothing...
        Code:
        <form:errors path="*" />
        When I try to display them with this code - everything is OK.

        Code:
          <c:forEach items="${flowRequestContext.messageContext.allMessages}" var="message">
            <c:if test="${message.severity eq 'Error'}">
              <div class="error-msg">${message.text}</div>
            </c:if>
          </c:forEach>
        It's not clear fo me, how will spring know about webflow's error messages which are in messageContext?

        Comment


        • #5
          Well, take a close look at the ref manual and swf-booking-mvc sample in this area... I suspect you're either missing a model declaration on your view-state or you're not adding the messages with the right source, which should be the fieldName for property failures, null for global failures.

          Keith

          Comment


          • #6
            Solved

            Hy,

            After some debugging and trial i found out that the path to our "model" was the problem.
            First i defined the model to be in the flowContext and also referenced it like this : flowContext.registerForm

            Spring WebFlow and the Error Tags or rather the Binding Code seem to have differing concepts about the use of dots.
            Dont remember which one exactly but one of those two uses dots like jstl (dots denote a property), the other one looks out for a bean named "flowContext.registerForm" (=one String)

            i just had to get rid of the flowContext prefix when not necessary and it worked as supposed.

            bye.

            Comment


            • #7
              solved

              Keith, icewolf thanks for help! path="registrationModel.*" instead of path="*" solved this problem

              Comment


              • #8
                I am able to display the message using the above tips for message context but the error message will not be retained if you refresh the page.

                Is
                requestContext.getMessageContext().addMessage(new MessageBuilder().error().defaultText("error msg").build());
                same as putting the error message in request scope?
                What should i be doing if i want to retaine the error message even after refreshing? Or how can i save MessageContext object in flow scope as its not Serializable (flow scope can store only Serializable objects) ?

                Thanks in advance.
                Last edited by reena; Jul 10th, 2009, 01:17 AM.

                Comment


                • #9
                  excuse me,
                  i've the same problem of post 4 (dabasov) how to fix it?

                  - i've just checked attribute model of view-state
                  - i've just checked correct MessageContext use
                  - i've tried:

                  Code:
                    <c:forEach items="${flowRequestContext.messageContext.allMessages}" var="message">
                      <c:if test="${message.severity eq 'Error'}">
                        <div class="error-msg">${message.text}</div>
                      </c:if>
                    </c:forEach>
                  ALL WORK

                  - i've tried

                  Code:
                  <form:errors path="*" />
                  <form:errors path="mymodel.*" />
                  <form:errors path="currentFormObject" />
                  ... and no errors were watched...

                  Anyone could help me?

                  Thanks


                  One other question... with spring 3 + swf 2 what is prefer to use : Errors or MessageContext? (Becouse in this moment wiht Errors everything work)
                  Last edited by foxmarco; Nov 3rd, 2010, 11:01 AM.

                  Comment


                  • #10
                    any idea? or soluzion?

                    thanks

                    Comment

                    Working...
                    X