流量取决于外部参数? [英] Flow depending on external parameter?
问题描述
我正在构建一个简单的POC来进行Faces Flow实验.
I'm building a simple POC to experiment with Faces Flow.
- 第1页:显示公司列表.用户选择公司A,然后转到第2页.
-
第2页:在选定的公司页面上,用户单击命令链接以启动向导以创建要添加到公司A的新员工.
- page 1: displays a list of companies. The user selects company A then goes to page 2.
page 2: on the selected company page, the user clicks a commandLink to start a wizard to create a new employee to be added to the company A.
在场景中,我有一个@FlowScoped("addNewUsertoCompanyFlow")
bean MyFlowBean
.
Behing the scenes I've got a @FlowScoped("addNewUsertoCompanyFlow")
bean MyFlowBean
.
在@PostConstruct
方法中,MyFlowBean
需要从服务(@Inject
)中获取与公司A相对应的对象.
In its @PostConstruct
method, the MyFlowBean
needs to fetch an object corresponding to the company A from a service (@Inject
).
让MyFlowBean知道公司A的ID以便它可以从服务中获取它的正确方法是什么?
What's the right way to let MyFlowBean know about the ID of the company A so that it can fetch it from the service ?
谢谢.
推荐答案
好的,我想出了一个解决方案.关键不是使用流支持bean @PostConstruct,而是使用流初始化程序,我可以在其中获取请求参数.
Ok, I came up with a solution. The key was not to use the flow backing bean @PostConstruct but rather use the flow initializer, where I can grab request parameters.
因此,我在表单中使用了一些其他输入,将开始我的流程:
So I'm using some additional input in the form that will start my flow:
<h:form id="myForm" prependId="false">
<h:commandLink value="Enter myFlow" action="my-flow"/>
<h:inputHidden id="parameter" name="parameter" value="8"/>
</h:form>
在流定义中,我为流定义了一个初始化程序,在流支持bean中调用了一些方法
In my flow definition I've defined an initializer for the flow, calling some method in the flow backing bean
@Produces @FlowDefinition
public Flow defineFlow(@FlowBuilderParameter FlowBuilder flowBuilder) {
String flowId = "my-flow";
flowBuilder.id("", flowId);
flowBuilder.initializer("#{myFlowBean.startFlow()}");
...
}
然后,我在后备bean中抓取了该参数.
I've then grabbed the parameter inside the backing bean.
@Named
@FlowScoped("my-flow")
public class MyFlowBean implements Serializable {
public void startFlow() {
String parameter = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("parameter");
//now do sthg with the parameter, such as fetching data from an injected service
....
}
}
当然,也可以在流定义级别做到这一点
Of course it's also possible to do that at the flow definition level
flowBuilder.initializer("#{trainingFlowBean.startFlow(param['parameter'])}");
并在startFlow方法中只有一个参数
and just have a parameter in the startFlow method
public void startFlow(String parameter) {
...
}
这篇关于流量取决于外部参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!