Mic*_*idt 9 java jsf spring spring-webflow
我view-state在flow.xml中有不同之处.所有这些州都有相同的观点.现在我想设置一个变量,它只包含一个String,并在视图文件中调用它来自定义内容.
这是我的文件:
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>
Run Code Online (Sandbox Code Playgroud)
在这个文件中,我需要一个带有视图状态ID值的变量,例如"rcarch".
rcmembers.xhtml 只是我要调用变量的代码部分
<p:panel id="panel" header="Memberslist of **Here comes the value of the variable">
Run Code Online (Sandbox Code Playgroud)
希望你能理解我的问题......
小智 8
您有两种选择:
首先,您可以在流定义级别定义它并直接将其公开给视图:
<on-entry>
<set name="flowScope.myView" value="flowRequestContext.currentState.id"/>
</on-entry>
Run Code Online (Sandbox Code Playgroud)
或者您可以将流上下文传递给控制器,然后在那里公开它:
<evaluate expression="RCHtmlCache.getCommunityList(flowRequestContext)" result="flowScope.members"/>
Run Code Online (Sandbox Code Playgroud)
在控制器上:
public String getCommunityList(RequestContext context) {
context.getFlowScope().put("myView", context.getCurrentState().getId());
...
}
Run Code Online (Sandbox Code Playgroud)
希望有所帮助
有些用户在这个问题之后问我,如何用String值设置一个简单的变量.所以xpadro的答案帮助了我很多,但有些用户点击这个问题知道如何用字符串值设置一个简单的变量.所以我想在这里发布答案:
使用xpadro代码,只需将值替换为您想要包围的字符串':
<set name="viewScope.variable" value="'String you want'" />
Run Code Online (Sandbox Code Playgroud)
就像xpadro所说的那样,set标签应该留在on-entry...
并且要知道Scope你应该使用哪个,请看http://static.springsource.org/spring-webflow/docs/2.0.x/reference/html/ch03s05 .html.
希望我可以帮助那个人:)
| 归档时间: |
|
| 查看次数: |
16716 次 |
| 最近记录: |