本文介绍了WELD-001303在直接访问时没有作用域类型javax.faces.flow.FlowScope的活动上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从本周开始以来,我就在使用JSF 2.2(用于CDI的MyFaces实现v2.2.6和Weld v2.2.7.Final),并且遇到了以下问题:我无法直接访问流入口点和我的兄弟.

I am playing with JSF 2.2 (MyFaces implementation v2.2.6 and Weld v2.2.7.Final for CDI) since the beginning of the week and I'm facing the following problem : I can't directly access a flow entry point with my brother.

例如:

我的Web应用程序包含一个名为"create"的流,该流允许在数据库中创建记录.我希望能够在浏览器地址栏中输入URL http://my.domain/webapp/create/create.jsf.

My webapp contains a flow named 'create' which permits to create a record in the database.I would like to be able to enter the URL http://my.domain/webapp/create/create.jsf in my browser address bar.

这样做时,页面无法正确呈现,并且以下日志显示在服务器中

When I do so, the page doesn't correctly render and the following log appears in the server

我在做什么错?不可能吗?我希望它应该!

What am I doing wrong ? Shouldn't it be possible ? I hope it should !

当我在流程之外创建页面时,没有任何问题,只有一个commandButton重定向到流程入口点.当我观看源代码时,尽管尚未访问该流,但似乎已经为该流创建了一个ID.这让我认为FlowScoped的设计不佳.而且,这样的解决方法(启动器"页面)破坏了我自己的设计和最终用户的体验.

I haven't any problem when I create a page, outside of the flow, having only one commandButton redirecting to the flow entry point.When I watch the source code, it seems that an id for the flow have already been created despite of the flow was not already accessed.That make me think FlowScoped is poorly designed.Moreover, such a work around (a 'launcher' page) breaks my own design and the end user experience.

有哪些可用的解决方案?

What are the available solutions ?

以下是一些示例代码:

create.xhtml

<h1>Create record</h1>
<h:form id="create-record" prependId="false">
    <label for="name">Name</label>
    <h:inputText id="name" value="#{createController.name}" />
    <h:commandButton title="Abandon" value="Abandon" id="abandon" action="returnFromCreate" immediate="true" />
    <h:commandButton title="Validate" value="Validate" id="validate" action="#{createController.create()}" />
</h:form>

CreateController

package my.company;

import java.io.Serializable;

import javax.faces.flow.FlowScoped;
import javax.inject.Inject;
import javax.inject.Named;

@Named
@FlowScoped("create")
public class CreateController implements Serializable {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String create() {
        // TODO
        return "returnFromCreate";
    }
}

xhtml启动器"

<h:form>
    <h:commandButton action="create" value="Go" />
</h:form>

create-flow.xml仅包含一个流返回"指令.

create-flow.xml only contains a "flow-return" directive.

推荐答案

该异常表明您已导航到页面,但您不在流中.您应该检查链接是否确实进入了流程,但是在此之前,请检查是否启用了客户端窗口api(javax.faces.CLIENT_WINDOW_MODE),因为Faces流程依赖于此功能. MyFaces 2.2 Faces Flow实施效果很好,即使在复杂的情况下(如嵌套流程),Mojarra的实施也无法处理,并且符合规范.

That exception indicates that you have navigated to the page, but you are not inside the flow. You should check if the link is really entering into the flow, but before that, check if client window api is enabled or not (javax.faces.CLIENT_WINDOW_MODE) because faces flow relies on this feature. MyFaces 2.2 Faces Flow implementation works very well, even with complex situations like nested flows that the implementation from Mojarra can't deal with, and is spec compliant.

Michael Kurz博客的 JSF 2.2实时系列中有一些关于JSF 2.2功能的很好的例子.这些示例适用于JF实现,MyFaces和Mojarra.在 Github jsflive 上查看Faces Flow的示例.

In JSF 2.2 live series from Michael Kurz Blog there are some good examples about JSF 2.2 features. The examples works for both JSF implementations, MyFaces and Mojarra. Check the example for Faces Flow on Github jsflive.

这篇关于WELD-001303在直接访问时没有作用域类型javax.faces.flow.FlowScope的活动上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 21:57