Announcement Announcement Module
Collapse
No announcement yet.
How to display informational messages using MessageContext Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to display informational messages using MessageContext

    I'm a swf newbie, and I thank SpringSource for this great technology...

    I'm perplexed as to how to display informational messages from a MessageContext that were set within a custom action. The documentation states "Use messageContext to access a context for retrieving and creating flow execution messages,
    including error and success messages. See the MessageContext Javadocs for more information." Okay, so I do that and no further information can be found. Also, I can't seem to find any examples of of displaying "success" or other non-error messages in the sample apps, or examples in this forum.

    Well, I'm a resourceful guy, so I tried using JSTL to iterate over the messages in a JSP:

    Code:
    <c:forEach items="${messageContext.allMessages}" var="message">
       ${message.text}
    </c:forEach>
    But no messages show up.

    So FINALLY, I try this hack in my action code:

    context.getFlashScope().put("messageContext", context.getMessageContext());

    And the above works.

    Surely there must be a better way to do this?!?

    Thanks for your help.

  • #2
    You can access flowRequestContext.messageContext. We should consider making the messageContext available directly as a model attribute in a future release.

    Keith

    Comment


    • #3
      Duh... Thanks Keith.

      It seems like I should have figured that one out pretty easily, but I think the way the word "request" is used in swf has been confusing me. I've finally got it through my thick skull that a swf "request" is not an HTTP request. So, I guess I didn't think the request context available in the page would be the same one that was part of the original request.

      My info messages can now be displayed with this:

      Code:
        <c:forEach items="${flowRequestContext.messageContext.allMessages}" var="message">
          <c:if test="${message.severity eq 'Info'}">
            <div class="info-msg">${message.text}</div>
          </c:if>
        </c:forEach>
      Seems a bit verbose. Maybe an info message tag is in the cards for SWF as well?

      Thanks for the great work. SWF is a real gem.

      Andrew

      Comment


      • #4
        Originally posted by insomniac View Post
        I'm a swf newbie, and I thank SpringSource for this great technology...

        I'm perplexed as to how to display informational messages from a MessageContext that were set within a custom action. The documentation states "Use messageContext to access a context for retrieving and creating flow execution messages,
        including error and success messages. See the MessageContext Javadocs for more information." Okay, so I do that and no further information can be found. Also, I can't seem to find any examples of of displaying "success" or other non-error messages in the sample apps, or examples in this forum.

        Well, I'm a resourceful guy, so I tried using JSTL to iterate over the messages in a JSP:

        Code:
        <c:forEach items="${messageContext.allMessages}" var="message">
           ${message.text}
        </c:forEach>
        But no messages show up.

        So FINALLY, I try this hack in my action code:

        context.getFlashScope().put("messageContext", context.getMessageContext());

        And the above works.

        Surely there must be a better way to do this?!?

        Thanks for your help.

        I tried the above but I am getting the below error

        Caused by: org.springframework.webflow.execution.repository.s napshot.SnapshotCreationException: Could not serialize flow execution; make sure all objects stored in flow or flash scope are serializable
        at org.springframework.webflow.execution.repository.s napshot.SerializedFlowExecutionSnapshot.<init>(Ser ializedFlowExecutionSnapshot.java:74)
        at org.springframework.webflow.execution.repository.s napshot.SerializedFlowExecutionSnapshotFactory.cre ateSnapshot(SerializedFlowExecutionSnapshotFactory .java:70)
        at org.springframework.webflow.execution.repository.s napshot.AbstractSnapshottingFlowExecutionRepositor y.snapshot(AbstractSnapshottingFlowExecutionReposi tory.java:75)
        at org.springframework.webflow.execution.repository.i mpl.DefaultFlowExecutionRepository.putFlowExecutio n(DefaultFlowExecutionRepository.java:123)
        at org.springframework.webflow.executor.FlowExecutorI mpl.resumeExecution(FlowExecutorImpl.java:165)
        at org.springframework.webflow.mvc.servlet.FlowHandle rAdapter.handle(FlowHandlerAdapter.java:183)
        at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:875)
        at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:807)
        at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:571)
        ... 34 more
        Caused by: java.io.NotSerializableException: org.springframework.binding.message.DefaultMessage Context
        at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1108)
        at java.io.ObjectOutputStream.writeObject(ObjectOutpu tStream.java:324)
        at java.util.HashMap.writeObject(HashMap.java:1040)
        at sun.reflect.GeneratedMethodAccessor178.invoke(Unkn own Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)

        Thanks in advance.

        Comment


        • #5
          Originally posted by insomniac View Post
          Duh... Thanks Keith.

          It seems like I should have figured that one out pretty easily, but I think the way the word "request" is used in swf has been confusing me. I've finally got it through my thick skull that a swf "request" is not an HTTP request. So, I guess I didn't think the request context available in the page would be the same one that was part of the original request.

          My info messages can now be displayed with this:

          Code:
            <c:forEach items="${flowRequestContext.messageContext.allMessages}" var="message">
              <c:if test="${message.severity eq 'Info'}">
                <div class="info-msg">${message.text}</div>
              </c:if>
            </c:forEach>
          Seems a bit verbose. Maybe an info message tag is in the cards for SWF as well?

          Thanks for the great work. SWF is a real gem.

          Andrew
          I've read the above post but would like to ask you guys..
          how about using Spring MVC 2.5.6.SEC01 and WF 2.0.9.RELEASE?
          i think, a lot of changes was made..

          please teach me the right way..
          thanks a lot.

          Comment

          Working...
          X