2

我在 Faces Flow 中看到的每个示例都包含仅在特定流程中使用的专有视图。我想做的是创建一个几乎完全由视图组成的流程,这些视图将在多个流程中使用,和/或可能在流程之外使用。这种视图的可重用性是可能的,还是 Faces Flows 不应该以这种方式使用?

JavaEE 7 文档中的 Faces Flow 示例

4

1 回答 1

3

Faces Flow 基本上是由 JSF 视图组成(或可以是),它们本身是可重用的。如果你参考这篇文章

JSF 2.2 中的流有哪些新功能?

应用程序的流程不再局限于页面之间的流程,而是定义为“节点”之间的流程。有五种不同类型的节点:

查看:应用程序中的任何 JSF 页面

方法调用:通过 EL 从流程图调用应用程序逻辑

Switch : 基于布尔 EL 的流程图中的导航决策

流调用:带参数调用另一个流并接收返回值

Flow Return : 返回调用流

第一点本身就回答了你的问题!


从 OP 编辑​​ (@jdessey)

我已经在测试中确认了接受的答案,并想在实施中分享一些注意事项。

Programmatic flow definition (i.e. @FlowDefinition annotation) is only processed if the class that contains the annotated method is itself a normal scoped CDI bean such as `@ApplicationScoped`. (Might be a bug - I'm using JSF 2.2.4 and Weld 2.0.4)
When defining the view node using FlowBuilder.viewNode(String viewNodeId, String vdlDocumentId), the document id must be the absolute path to the .xhtml file. This is in the javadoc but not intuitive IMO because since 2.0 we are used to implicit navigation.

代码:

@ApplicationScoped
public class MyFlow implements Serializable {

    @Produces @FlowDefinition
    public Flow defineFlow(@FlowBuilderParameter FlowBuilder flowBuilder) {
        flowBuilder.id("", "myFlow");
        flowBuilder.viewNode("anyView", "/absolutePathToView.xhtml").markAsStartNode();
        return flowBuilder.getFlow();
    }
}

现在要导航到这个流程,只需使用“myFlow”作为隐式导航案例,例如:

<p:menuitem value="Begin Flow" action="myFlow" />
于 2013-10-15T11:30:10.037 回答