10

I've different view-state's in flow.xml. All of theses states have the same view. Now i want to set a variable which includes just a String und call it in the view-file to customize the content.
Here are my files:
flow.xml: for the example two of the view-state's

<view-state id="rcpm" view="rc/rcmembers.xhtml">
    <on-entry>
        <evaluate expression="RCHtmlCache.getCommunityList('rcpm')"
            result="flowScope.members" />
    </on-entry>
</view-state>

<view-state id="rcarch" view="rc/rcmembers.xhtml">
   <on-entry>
        <evaluate expression="RCHtmlCache.getCommunityList('rcarch')"
            result="flowScope.members" />
    </on-entry>
</view-state>

In this file i need a variable with the value of the view-state ID, so e.g "rcarch".

rcmembers.xhtml just the part of the code where i want to call the variable

<p:panel id="panel" header="Memberslist of **Here comes the value of the variable">

Hope you understand my problem...

rptmat57
  • 3,643
  • 1
  • 27
  • 38
Michael Schmidt
  • 9,090
  • 13
  • 56
  • 80

3 Answers3

8

You have two options:

First, you can define it at flow definition level and expose it to the view directly:

<on-entry>
   <set name="flowScope.myView" value="flowRequestContext.currentState.id"/>
</on-entry>

Or you could pass the flow context to the controller and then expose it there:

<evaluate expression="RCHtmlCache.getCommunityList(flowRequestContext)" result="flowScope.members"/>

On the controller:

public String getCommunityList(RequestContext context) {
   context.getFlowScope().put("myView", context.getCurrentState().getId());
   ...
}

Hope that helps

Michael Schmidt
  • 9,090
  • 13
  • 56
  • 80
xpadro
  • 183
  • 1
  • 3
  • BIG THANKS! Your first option works absolutely perfect! Thanks a lot! I didn't know the command "flowRequestContext.currentState.id". Finally :) Thanks Again! Helps me a lot! – Michael Schmidt Mar 08 '13 at 07:35
  • 1
    You are welcome :-) Just made a post about communication in Spring Web Flow 2. It may be useful for this case and others related: [blog](http://xpadro.blogspot.com.es/2013/04/communication-in-spring-webflow-2.html) – xpadro Apr 04 '13 at 08:58
8

Some users asked me after this question, how to set a simple variable with a String value. So the answer by xpadro helpds ME a lot, but some users click on this question to know how to set a simple variable with a string value. So I want to post here the answer also for that:
Use the code by xpadro and just replace the value with the string you want surrounded with ' :

<set name="viewScope.variable" value="'String you want'" />

Like xpadro said, the set tag should stay inside the on-entry...
And to know which Scope you should use, take a look at http://static.springsource.org/spring-webflow/docs/2.0.x/reference/html/ch03s05.html.

Hope i can help someone with that :)

Michael Schmidt
  • 9,090
  • 13
  • 56
  • 80
2

Why not create a subflow for this view-state?

This way you could have an input for you variable and call it from anywhere. No need to have multiple identical view states.

rbento
  • 9,919
  • 3
  • 61
  • 61
rptmat57
  • 3,643
  • 1
  • 27
  • 38
  • I have a scenario wherein, I need to jump from one flow to another sub-flow to and fro, I am doing that using ``. My question is whether the variables defined using `` of that particular flow gets instantiated everytime that flow is invoked or only once? – Nisarg Patil Jan 15 '18 at 09:29
  • if the var is in the subflow, every time it is invoked – rptmat57 Jan 15 '18 at 13:40