Results 1 to 9 of 9

Thread: Unable to get parameter from requestParameters

  1. #1
    Join Date
    Aug 2009
    Posts
    12

    Talking Unable to get parameter from requestParameters

    I'm posting this as I took ages finding the solution and may help someone.

    I was not able to get a parameter using requestParameters during the following -

    <view-state id="reviewProducts">

    <on-render>
    <set name="category" value="requestParameters.displayByCategory" />
    <evaluate expression="service.findProductsByCategory(categor y)" result="viewScope.products" result-type="dataModel" />
    </on-render>

    The problem is that requestParameters looses scope of its values <on-render> and the solution is to do a <set> during <on-entry> e.g.

    <view-state id="reviewProducts">
    <on-entry><set name="category" value="requestParameters.displayByCategory" /></on-entry>
    <on-render>
    <set name="category" value="requestParameters.displayByCategory" />
    <evaluate expression="service.findProductsByCategory(categor y)" result="viewScope.products" result-type="dataModel" />
    </on-render>

    The submission to the flow was via - <a href="/company/flows/main?displayByCategory=toys">

  2. #2
    Join Date
    Nov 2008
    Posts
    742

    Default

    This is a tricky subject, one I think that should be better covered in the SWF reference guide when explaining the implications of the POST-REDIRECT-GET pattern.

    As you mentioned, requestParameters (and anything in requestScope) is accessible in the on-entry section of a view-state, but not in the on-render section.

    When the user invokes SWF in a POST request, this lasts into the on-entry section. SWF then issues a REDIRECT to the user, which blows away anything in the request. The on-render actions only occur in the GET request for the new view.

  3. #3
    Join Date
    Apr 2009
    Posts
    20

    Default

    Thanks InverseFalcon , you saved my day!

    This is a tricky subject, one I think that should be better covered in the SWF reference guide when explaining the implications of the POST-REDIRECT-GET pattern.
    +1

  4. #4
    Join Date
    Jan 2010
    Posts
    4

    Default

    Hi,
    after reading this thread, I sadly have the problem, that even in the on-entry section no requestScope parameter is available. Since I'm new to spring web flow it's maybe a beginner's mistake. But at the moment I really don't understand what might be wrong with my code. I hope you can help me with your great experiences.
    JSP:
    HTML Code:
    <form method="post" name="sessionOverviewForm">	
    <c:if test="${not empty sessions}"> 
       <c:forEach var="session" items="${sessions}">
       ...
       <td>
         <a href="javascript:document.sessionOverviewForm._eventId.value='deletesession'; document.sessionOverviewForm.sessionId.value='${session.ID}';document.sessionOverviewForm.submit();">
    							<img src="<c:url value="/images/btn_delete.gif"/>" border="0"/>
         </a>
       </td>
       <input type="hidden" name="sessionId" value="" />
       ...
    Also setting the value in hidden input field directly doesn't change anything, it's no javascript error.

    Flow.xml
    HTML Code:
    <view-state id="listSessions" view="measurement/session/listSessions">
      <on-render>
    	<evaluate expression="measurementService.getSessionList()" result="flowScope.sessions" />
      </on-render>
      <transition on="addsession" to="detailsSession" />
      <transition on="deletesession" to="deleteSession" />
    </view-state>
    
    <end-state id="deleteSession">
      <on-entry>
         <evaluate expression="measurementService.deleteSession(requestParameters.sessionId)" />
      </on-entry>
    </end-state>
    Changing expression method parameter to requestScope.sessionId doesn't work.
    First I thought, maybe this doesn't work in end-states, but it doesn't play a role. With a view-state I get the same error.
    There's simply no request parameter in map contained, so I get a javax.el.ELException: java.lang.UnsupportedOperationException

  5. #5
    Join Date
    Aug 2009
    Posts
    12

    Default Unable to get parameter from requestParameters

    Request parameters are placed on the end of a url after a question mark e.g. <a href="http://localhost:8080/App/Some.action?sessionId=1234"> would send a request parameter of sessionId value 1234.

    You seem to be setting form values, then submitting a form. The Spring webflow examples will give you lots of examples for accessing form values from within a webflow definition.

  6. #6
    Join Date
    Mar 2009
    Posts
    15

    Thumbs up

    If you need to pass the request parameter when the user clicks the link, then you can use something like this:
    <h:commandLink....>
    <faram name="nameofParam" value="#{flowScope.parameter}"/>
    </h:commandLink>

    Now on the flow you can access the param using something like this:
    <transition....
    <set name="flowScope.selectedLink" value="requestParameters.nameofParam" />

    </transition>

    Hope this helps.

    Let me know if i can help further.

  7. #7
    Join Date
    Jan 2010
    Posts
    4

    Default

    Thanks for your fast responses. But sadly even using a link with &sessionId=#somenumber added does produce the same error. Generated Html Code is correct and variable names, too. At the moment I'm not quite sure anymore, what this error does mean. Maybe I'm absolutely on the wrong way. Here's the error that is produced:
    Code:
    exception
    
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@3e74ad targetAction = [EvaluateAction@18f6407 expression = measurementService.deleteSession(requestScope.sessionId), resultExposer = [null]], attributes = map[[empty]]] in state 'deleteSession' of flow 'measurement/session' -- action execution attributes were 'map[[empty]]'
    
    root cause
    
    org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@3e74ad targetAction = [EvaluateAction@18f6407 expression = measurementService.deleteSession(requestScope.sessionId), resultExposer = [null]], attributes = map[[empty]]] in state 'deleteSession' of flow 'measurement/session' -- action execution attributes were 'map[[empty]]'
    
    root cause
    
    org.springframework.binding.expression.EvaluationException: An ELException occurred getting the value for expression 'measurementService.deleteSession(requestScope.sessionId)' on context [class org.springframework.webflow.engine.impl.RequestControlContextImpl]
    
    root cause
    
    javax.el.ELException: java.lang.UnsupportedOperationException
    This is excerpt from MeasurementServiceImpl:
    Code:
    @Service("measurementService")
    public class MeasurementServiceImpl extends EObjectImpl implements MeasurementService {
      ...
      public void deleteSession(Long id) {
         sessionDao.delete(id);
      }
    JSP:
    HTML Code:
    <td>
    	<a href="${flowExecutionUrl}&_eventId=deletesession&sessionId=${session.ID}">
    		<img src="<c:url value="/images/btn_delete.gif"/>" border="0"/>
    	</a>
    </td>
    Flow.xml:
    HTML Code:
    <end-state id="deleteSession">
    	<on-entry>
    		<evaluate expression="measurementService.deleteSession(requestScope.sessionId)" />
    	</on-entry>
    </end-state>
    PS: requestParameters.sessionId does not work, too
    PPS: The code with the commandLink looks like JSF. Sadly I don't want to use JSF, because in the future another person does the HTML/JSP coding. To give him JSP code is quite OK (of course, better I should take tapestry). That's why I chose Tiles as template engine. JSF is much too complex for a web designer.

    I'm very grateful for your help!!

  8. #8
    Join Date
    Mar 2009
    Posts
    15

    Thumbs up

    you can use the spring web flows tag for command link instead of <h:commandLink too.

  9. #9
    Join Date
    Jan 2010
    Posts
    4

    Default

    Thanks a lot for your help...
    Perfect!
    It works now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •