2

My use case: the user choose a questionnaire in a form. When the form is submitted, a faces-flow is started to display the questions of the questionnaire.

To send the questionnaire to the flow, in the bean of the flow I inject the CDI bean of the page which contains the form.

I wonder if there are other ways to send the questionnaire to the flow. If there are several ways, what's the best one?

4

3 回答 3

2

您可以通过表单传递参数,并在流程初始化时调用的初始化方法中获取它们。

表单(只需将 inputHidden 参数替换为您用于选择问卷的任何参数)

<h:form id="myForm" prependId="false">
    <h:commandLink value="Enter myFlow" action="my-flow"/>
    <h:inputHidden id="parameter" name="parameter" value="8"/>
</h:form>

流动

@Produces @FlowDefinition
public Flow defineFlow(@FlowBuilderParameter FlowBuilder flowBuilder) {
String flowId = "my-flow";
    flowBuilder.id("", flowId);
    flowBuilder.initializer("#{myFlowBean.startFlow()}");
    ...
}

支持豆

@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 the questionnaire
    ....
    }
}

有关更多详细信息,请参阅此答案

于 2014-01-21T08:46:33.590 回答
0

除了“thomas.g”的有用答案:

我有同样的问题,但无法用 hiddenInput 方法解决它。尽管有 prependId="false" 属性,但我使用的 primefaces p:dataTable 元素更改了隐藏输入字段的 id 和名称。该问题可以通过 h:commandLink 元素中的 f:param 元素来解决:

<h:commandLink value="Enter myFlow" action="my-flow" >
    <f:param name="parameter" value="8"/>
</h:commandLink>

我希望这可能对有类似问题的人有所帮助。

于 2015-09-24T10:44:46.877 回答
0

这可以使用初始化标记在流 xml 文件中完成

   <initializer>
       #{myFlowBean.startFlow()}
   </initializer>

在流范围 bean 中调用您的初始化方法

于 2018-03-01T07:27:59.637 回答