Vinay
Vinay

Reputation: 86

Forwarding a request in Spring WebFlow

Currently my application logic is using request parameters to execute the logic. In my new requirement I can also get a request that will only have a db key(db will have the values) as a request parameter. I can fetch the data from database but the problem is now my existing logic/flow will not work as it expects the data in parametermap.

In spring-mvc I can just forward the request again and append the parameters to request

@Controller
public class TestController {
    @RequestMapping(value="/test")
    public String showTestPage() {
        return "forward:/test2?param1=foo&param2=bar";
    }
}

@Controller
public class TestController2 {
    @RequestMapping(value="/test2")
    public String showTestPage(HttpServletRequest request) {
        String param1 = request.getParameter("param1");
        String param2 = request.getParameter("param2");
        return "testPageView";
    }
}

But in spring-webflow I am not sure how to replicate the same behavior as it works on states instead of request mapping. Can anyone please let me know if there is a way to forward in spring-webflow after adding parameters.

Upvotes: 0

Views: 1886

Answers (2)

Vinay
Vinay

Reputation: 86

In flow xml add this :

<view-state id="viewname" view="flowRedirect:appName?#{flowScope.jobId}

so when you transit to this view state it will redirect the url back to server with the request params you want. But this will hit the web and then the server again, I want the request to stay on the server side only

Upvotes: 0

Philipp Sander
Philipp Sander

Reputation: 10249

Update:

Sorry i got your question wrong.

In WebFlow you have view-states which have transitions to the next state. If you want to transmit parameters you can do it like this:

flow.xml:

<view-state id="test" view="test.jsp>
    <transition on="toTest2" to="test2" />
</view-state>

<view-state id="test2" view="test2.jsp>
    <on-render>
        <evaluate expression="test2Delegate.doSomething(requestParameters.param2, requestParameters.param2)" 
    </on-render>
</view-state>

Test.jsp:

<a href="${flowExecutionUrl}&_eventId=toTest2&param1=foo&param2=bar" />

Java:

@Component
public class Test2Delegate {

    public void doSomething(String param1, String param2) {

        //doSomething
    }
}

I would recommend read the Spring Web Flow Reference Guide

Upvotes: 1

Related Questions