【问题标题】:Faces flow with reusable views带有可重用视图的人脸流动
【发布时间】:2013-10-22 10:49:03
【问题描述】:

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

Faces Flow example from JavaEE 7 doc

【问题讨论】:

  • 随时用您测试过的内容更新我的答案。最好在答案字段中而不是在问题本身中发布答案!
  • 我编辑了答案(看起来它将在同行评审后可用)。感谢您的提示 - 我仍然习惯这种格式。
  • 您的编辑已被拒绝,但我已恢复 ;-)

标签: jsf view reusability jsf-2.2 faces-flow


【解决方案1】:

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

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

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

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

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

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

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

流程返回:返回调用流程

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


从 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" />

【讨论】:

    猜你喜欢
    • 2016-08-09
    • 1970-01-01
    • 2012-01-27
    • 1970-01-01
    • 2019-07-15
    • 2019-06-10
    • 1970-01-01
    • 2021-08-05
    • 2013-10-16
    相关资源
    最近更新 更多