Announcement Announcement Module
Collapse
No announcement yet.
Skip search results Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Skip search results

    Hi,
    I'm stuck with implementation of the following scenario: if search brings just one result the 'Results' view should be skipped and user should be presented with 'details' page for the found item. Currently we have implementation almost identical to hotels sample :
    Code:
    	
    ...
    <transition on="searchSomething"  >
    			...
    			<evaluate expression="searchService.search(flowScope.searchCriteria, messageContext)"
    			    result="viewScope.results" result-type="dataModel" />
    			 <render fragments="searchResultsFragment" />
    		</transition>
    ...
    I tried to replace it with following:

    Code:
    <action-state id="decideToSearchResultsOrEdit">
                    <evaluate expression="requestScope.results.rowCount != 1" />
                    <transition on="yes">
                            <render fragments="searchResultsFragment" />
                    </transition>
                    <transition on="no" to="editView">
                            ...
                    </transition>
          </action-state>
    
    <transition on="searchSomething" to="decideToSearchResultsOrEdit" >
    			
    			<evaluate expression="searchService.search(flowScope.searchCriteria, messageContext)"
    			    result="requestScope.results" result-type="dataModel" />
    			
    		</transition>
    but it fails with

    Caused by: java.lang.IllegalStateException: You can only resume paused view states, and state [ActionState@5f24672b id = 'decideToSearchResultsOrEdit', flow = 'menu', entryActionList = list[[empty]], exceptionHandlerSet = list[[empty]], actionList = list[[AnnotatedAction@4ef168d9 targetAction = [EvaluateAction@4b1aa70c expression = requestScope.results.rowCount > 0, resultExpression = [null]], attributes = map[[empty]]]], transitions = list[[Transition@42cd2b59 on = yes, to = [null]], [Transition@2bd90252 on = no, to = editView]], exitActionList = list[[empty]]] is not a view state - programmer error
    at org.springframework.webflow.engine.Flow.getCurrent ViewState(Flow.java:645)
    at org.springframework.webflow.engine.Flow.resume(Flo w.java:545)
    at org.springframework.webflow.engine.impl.FlowExecut ionImpl.resume(FlowExecutionImpl.java:259)
    ... 44 more
    First of all i don't understand why the flow is being resumed and why it was stopped on ActionState?
    And probably there are some other ways around?

    Any help is highly appreciated!

    Best regards, Eugene.

  • #2
    Originally posted by ebu View Post
    And probably there are some other ways around?
    Can you try changing the action-state to a decision state ?

    Something like,

    Code:
    <decision-state id="decideToSearchResultsOrEdit">
        <if test="yourTest()" then="searchResultsFragment" else="editView" />
    </decision-state>
    Vishwa

    Comment


    • #3
      I've changed the flow as you suggested and now it executes without exceptions but after that I can't get edit view to be filled with the returned item since decision-state does not allow any sets (except within on-exit, but then how to figure out what was decision?). The action state should be like this, probably I've simplified the sample too much:
      Code:
      <action-state id="decideToSearchResultsOrEdit">
                      <evaluate expression="requestScope.results.rowCount != 1" />
                      <transition on="yes">
                              <render fragments="searchResultsFragment" />
                      </transition>
                      <transition on="no" to="editView">
                              <set name="flowScope.agreementId" value="requestScope.results.wrappedData.get(0)" />
                      </transition>
            </action-state>
      Also can the "render fragments" be somehow used with a decision-state?

      Best regards, Eugene.

      Comment


      • #4
        I haven't used <render fragments...> much and I am doubtful if it works with states that are not view states. Are you sure it works for non-view states ?

        I'd try something like this..


        Code:
        <decision-state id="decideToSearchResultsOrEdit">
            <if test="yourTest()" then="searchResultsView" else="processEditAction" />
        </decision-state>
        
        <view-state id="searchResultsView" view="theViewName">
          <on-entry>
                <render fragments="searchResultsFragment" />
            </on-entry
        </view-state>
        
        <action-state id="processEditAction">
            <set name="flowScope.agreementId" value="requestScope.results.wrappedData.get(0)" />
          <transition on="success" to="editView"/>
        </action-state>
        i.e, to decide using decision state - if any intermediate processing needs to be done, dispatch to an action state and from there to a view state. If no processing is required then, directly take it to the view-state and restrict which fragments to show

        Comment


        • #5
          Finally it's appeared that the problem is in a4j:commandButton. It just does not trigger any transitions. It looks like similar issue was already raised here, but is there really no any way to use a4j:commandButton for transitions? The a4j:commandButton seems to be quite frequently discussed on this forum.

          Best regards, and thank you for your help!

          Comment

          Working...
          X