java Web Flow 中的简单变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15267107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simple Variable in Web Flow
提问by Michael Schmidt
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
在flow.xml 中有不同的。所有这些州都有相同的看法。现在我想设置一个只包含一个字符串的变量,并在视图文件中调用它来自定义内容。
这是我的文件:
flow.xml:例如视图状态的两个
<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".
在这个文件中,我需要一个带有视图状态 ID 值的变量,例如“rcarch”。
rcmembers.xhtmljust the part of the code where i want to call the variable
rcmembers.xhtml只是我想调用变量的代码部分
<p:panel id="panel" header="Memberslist of **Here comes the value of the variable">
Hope you understand my problem...
希望你明白我的问题...
采纳答案by xpadro
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
希望有帮助
回答by Michael Schmidt
Some users asked me after this question, how to set a simple variable with a String value. So the answer by xpadrohelpds 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 xpadroand just replace the value with the string you want surrounded with '
:
一些用户在这个问题之后问我,如何设置一个带有字符串值的简单变量。所以xpadro的回答对我有很大帮助,但是有些用户点击这个问题就知道如何用字符串值设置一个简单的变量。所以我想在这里发布答案:
使用xpadro的代码,只需用你想要的字符串替换值'
:
<set name="viewScope.variable" value="'String you want'" />
Like xpadrosaid, 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.
就像xpadro说的,set
标签应该留在on-entry
...
并且知道Scope
你应该使用哪个,看看http://static.springsource.org/spring-webflow/docs/2.0.x/reference/html/ch03s05 html的。
Hope i can help someone with that :)
希望我能帮助某人:)
回答by rptmat57
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.
这样你就可以为你的变量输入一个输入并从任何地方调用它。不需要有多个相同的视图状态。