Announcement Announcement Module
Collapse
No announcement yet.
<evaluate expression="" result="" /> Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • <evaluate expression="" result="" />

    Hi,

    Sorry, though I'm kinda frustrated trying to find good reference material on web flow...

    How exactly does evaulate expression work? I was unable to find a satisfactory detailed technical explanation on the reference guide?

    What I understood so far, is that if I return a boolean, that it can evaluate this result, and if true the flow can continue, if false the flow will not continue (transition).

    If the expression is calling a method and a method throws an exception, web flow seems to bomb out...

    What happens if I have a result that is returned from a method? How can I inform web flow not to transition in this case, since the return value is not a boolean?

    BTW, I bought the web flow book from ervacon, though its outdated and not as useful now that web flow 2.0 is out and drastically different....where can I get good docs to help me develop?

    Thanks,
    Josh

  • #2
    I think you have missunderstood the meaning of evaluate.

    Just take a look at the provided documentation:

    http://static.springframework.org/sp...-reference.pdf

    Read Chapter 2.6. Actions


    - Peter

    Comment


    • #3
      Hi Peter,

      Thanks for your reply.

      Though as I mentioned, I already read through the reference guide.

      Can you be more specific as to what I may have missed?

      Here is the section in partcular which is vague for the question I asked...how do I handle booleans if I have a result?

      4.6
      4.9. Transition actions

      A view-state transition can execute one or more actions before executing. These actions may return an error result to prevent the transition itself from executing. If an error result occurs, the view will re-render and should typically display an appropriate error message to the user.

      If the transition action invokes a plain Java method, the invoked method may return false to prevent the transition from executing. This technique can be used to handle exceptions thrown by service-layer methods. The example below invokes an action that calls a service and handles an exceptional situation:

      <transition on="submit" to="bookingConfirmed">
      <evaluate expression="bookingAction.makeBooking(booking, messageContext)" />
      </transition>


      public class BookingAction {
      public boolean makeBooking(Booking booking, MessageContext context) {
      try {
      bookingService.make(booking);
      return true;
      } catch (RoomNotAvailableException e) {
      context.addMessage(builder.error().
      .defaultText("No room is available at this hotel").build());
      return false;
      }
      }
      }

      Comment


      • #4
        I also think that the reference should give more details... not just a brief description and a sample.

        They should explain all attributes and what type of value they expect... and give a description of each attribute too.

        Comment


        • #5
          @Josh,

          how do I handle booleans if I have a result?
          In case you are using the <evaulate> tag within a <transition> tag and the method you evaluate returns a boolean of false the transition will not occur. This is just a special feature of the evalaute tag in case you use it in the mentioned context (within a transition tag).
          In general the evaluate tag allows you to execute a method on a bean and gives you the possibility to save the result via result="" attribute, e.g.:

          Code:
          <evaluate expression="foo.bar()" result="flowScope.resultVarName">
          So the result of the method bar will be saved under the name resultVarName.

          Does this answer you questions?
          Have you taken a look at the sample projects?

          @Guilherme ,

          I also think that the reference should give more details... not just a brief description and a sample.

          They should explain all attributes and what type of value they expect... and give a description of each attribute too.
          I think the term should is not appropriate. The SpringTeam could mention that you should read the reference documentation, that you should study the sample applications, that you should browse the forum that......
          Imho we get here some really cool stuff for free and my way to appreciate that is to read this forum regulary and try to answer some questions (I'm also "new" to SWF).

          - Peter

          Comment


          • #6
            Peter,

            I'm sorry. From my post looks like I don't appreciate the great work that th SpringTeam do. But I do appreciate very much.

            Also I appreciate your help too... you already helped me a lot (by anwser my posts or other people's)

            On the post I was trying to do a more like suggestion, not a hard critic. And looking again I think I didn't express myself the way I should. But I'm not an english speaker and sometimes I have this problems.

            About the reference documentation, there are parts that are just great, like the MVC, JSF and RichFaces integration. The forum also helps a lot but I can't find all I need...

            If you can please give me some indication about a good book on SWF2.0 I would appreciate that.

            Regards,

            Guilherme

            Comment


            • #7
              Guilherme,



              I guess SWF 2.0 is not available long enough for a book about it.

              I can strongly recommend to study the sample applications in combination with the available documentation.
              If you have afterwards questions I'm pretty sure that somebody in this forum can answer them (at least I will try )

              - Peter

              Comment


              • #8
                Code:
                <evaluate expression="foo.bar()" result="flowScope.resultVarName">

                What I'm trying to do, is in the above example, if foo.bar does not return a boolean, let's say a list of Strings, if the method throws an exception, how do I inform the transition not to continue?

                If foo.bar returned a boolean rather than a list of strings, then I could catch the exception in foo.bar and return false, though since it returns a list of strings, I can't do that...

                In SWF 2.0, I'm trying to figure out how to do a decision state and then transition.

                Thanks,
                Josh

                Comment


                • #9
                  Perhaps you can use the on-exception attribute in the transition tag.

                  See http://forum.springframework.org/sho...t=on-exception

                  - Peter

                  Comment


                  • #10
                    Ok, cool...that will get me going for now.

                    Is there some spring web flow wiki, would be nice to add this info as I'm unable to find it in the reference guide.

                    Comment


                    • #11
                      Actually, I need more help with these...is there a link to some technical details how this work?

                      I need to set some sort of error message if there is an exception and I'm transitioning

                      Code:
                      		<transition on-exception="java.lang.Exception" to="register">
                      			<set name="flashScope.register.alreadyRegisteredErrorMsg" value="'You have already registered'"/>
                      		</transition>

                      When I add the set name I get a stack overflow error

                      Code:
                      java.lang.StackOverflowError
                      	at java.lang.StringBuilder.append(StringBuilder.java:119)
                      	at java.lang.Object.toString(Object.java:219)
                      
                      ...
                      
                      	at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:72)
                      	at org.springframework.core.style.DefaultToStringStyler.styleValue(DefaultToStringStyler.java:91)
                      	at org.springframework.core.style.DefaultToStringStyler.styleField(DefaultToStringStyler.java:79)
                      	at org.springframework.core.style.ToStringCreator.append(ToStringCreator.java:156)
                      	at org.springframework.webflow.engine.impl.FlowExecutionImpl.toString(FlowExecutionImpl.java:520)
                      	at java.lang.String.valueOf(String.java:2827)
                      	at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:78)
                      	at org.springframework.core.style.DefaultToStringStyler.styleValue(DefaultToStringStyler.java:91)
                      	at org.springframework.core.style.DefaultToStringStyler.styleField(DefaultToStringStyler.java:79)
                      	at org.springframework.core.style.ToStringCreator.append(ToStringCreator.java:156)
                      	at org.springframework.webflow.engine.impl.RequestControlContextImpl.toString(RequestControlContextImpl.java:232)
                      	at java.lang.String.valueOf(String.java:2827)
                      	at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:78)
                      	at org.springframework.core.style.DefaultToStringStyler.styleValue(DefaultToStringStyler.java:91)
                      	at org.springframework.core.style.DefaultToStringStyler.styleField(DefaultToStringStyler.java:79)
                      	at org.springframework.core.style.ToStringCreator.append(ToStringCreator.java:156)
                      	at org.springframework.binding.expression.EvaluationAttempt.createToString(EvaluationAttempt.java:62)
                      	at org.springframework.binding.expression.SetValueAttempt.createToString(SetValueAttempt.java:51)
                      	at org.springframework.binding.expression.EvaluationAttempt.toString(EvaluationAttempt.java:58)
                      	at java.lang.String.valueOf(String.java:2827)
                      	at java.lang.StringBuffer.append(StringBuffer.java:219)
                      	at org.springframework.binding.expression.EvaluationException.defaultMessage(EvaluationException.java:58)
                      	at org.springframework.binding.expression.EvaluationException.(EvaluationException.java:36)
                      	at org.springframework.binding.expression.ognl.OgnlExpression.setValue(OgnlExpression.java:102)
                      	at org.springframework.webflow.action.SetAction.doExecute(SetAction.java:76)
                      	at org.springframework.webflow.action.AbstractAction.execute(AbstractAction.java:188)
                      	at org.springframework.webflow.execution.AnnotatedAction.execute(AnnotatedAction.java:145)
                      	at org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:51)
                      	at org.springframework.webflow.engine.ActionList.execute(ActionList.java:155)
                      	at org.springframework.webflow.engine.support.TransitionExecutingFlowExecutionExceptionHandler.handle(TransitionExecutingFlowExecutionExceptionHandler.java:109)
                      	at org.springframework.webflow.engine.FlowExecutionExceptionHandlerSet.handleException(FlowExecutionExceptionHandlerSet.java:113)
                      	at org.springframework.webflow.engine.State.handleException(State.java:222)
                      	at org.springframework.webflow.engine.impl.FlowExecutionImpl.tryStateHandlers(FlowExecutionImpl.java:615)
                      	at org.springframework.webflow.engine.impl.FlowExecutionImpl.handleException(FlowExecutionImpl.java:585)
                      	at org.springframework.webflow.engine.impl.FlowExecutionImpl.handleException(FlowExecutionImpl.java:590)
                      	at org.springframework.webflow.engine.impl.FlowExecutionImpl.handleException(FlowExecutionImpl.java:590)
                      	at org.springframework.webflow.engine.impl.FlowExecutionImpl.handleException(FlowExecutionImpl.java:590)
                      	at org.springframework.webflow.engine.impl.FlowExecutionImpl.handleException(FlowExecutionImpl.java:590)
                      	at org.springframework.webflow.engine.impl.FlowExecutionImpl.handleException(FlowExecutionImpl.java:590)
                      	at org.springframework.webflow.engine.impl.FlowExecutionImpl.handleException(FlowExecutionImpl.java:590)

                      Why? How do I properly use this?

                      Comment


                      • #12
                        I think if you would read the SWF 1.x documentation you will find something about it. I have quickly searched the SWF 2.x docu and only found it in the 1.0 to 2.0 Mappings section.
                        I have started with SWF 2.x and never had the motivation to read the 1.x documentation.
                        I'm sure the Webflow Team knows that the documentation is something which can be improved and if they find the time....

                        - Peter

                        Comment

                        Working...
                        X