可以从Servlet内部启动人脸流吗? [英] Can a faces flow be started from within a Servlet?

查看:97
本文介绍了可以从Servlet内部启动人脸流吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由servlet访问的服务,该服务将用户重定向到登录屏幕.支持Bean的范围目前已从@ConversationScoped更改为@FlowScoped,因为它更易于处理.

I have a service, accessed by a servlet, which redirects the user to a login screen. The backing beans' scope is currently being changed from @ConversationScoped to @FlowScoped, as it's easier to handle.

是否有一种方法可以直接从servlet内部初始化面部流,而无需通过隐式操作或JSF转发/重定向进行间接操作?

Is there a way to initialize a faces flow directly from within a servlet, without the indirection through an implicit action or a JSF forward/redirect?

我知道@FlowScope是一个JSF(2.2)范围,我想知道是否可能有一种方法,例如扩展FacesServlet或类似的东西.

I am aware that @FlowScope is a JSF (2.2) scope and I was wondering if there might be a way to e.g. extend the FacesServlet or something similar.

作为一种解决方法,我目前仅添加了带有按钮的视图,这使JSF可以进入流目录,但是我试图避免这种情况.

As a workaround, I currently just added view with a button, which makes a JSF forward to enter the flow directory, but I am trying to avoid this.

更新
我尝试了许多方法来自动"前进到流程中,而不必单击任何按钮,但是我总是得到一个No active contexts for scope type javax.faces.flow.FlowScoped.这是我的方法:

Update
I tried many approaches to 'automatically' forward into a flow, without having to click on any button, but I always get a No active contexts for scope type javax.faces.flow.FlowScoped. Here my approaches:

  1. f:viewAction

<f:metadata>
  <f:viewAction action="myFlow" />
</f:metadata>

这个命令似乎执行得太早了(无论如何).

This one seems to be executed too early (in any case).

f:event

<f:event type="preRenderView" listener="#{myBean.forwardToMyFlow()}" />

bean中的方法返回与f:viewAction中相同的结果.

The method in the bean returns the same outcome as in f:viewAction.

导航案例

<navigation-rule>
  <from-view-id>/myView.xhtml</from-view-id>
  <navigation-case>
    <from-outcome>myFlow</from-outcome>
    <to-view-id>/myFlow/myFlow.xhtml</to-view-id>
    <redirect />
    <to-flow-document-id />
  </navigation-case>
</navigation-rule>

我想念什么?

推荐答案

在阅读规格并摆弄流程之后,我终于找到了解决方案!
我在一个页面上有一个简单的页面:

I finally found a solution, after reading specs and fiddling around with flows!
I am having a page where I simply have:

<f:metadata>
    <f:viewAction action="#{bean.initFlow}" />
</f:metadata>

到目前为止,一切都很好,但诀窍在方法内部,您必须通过以下操作手动"初始化所需的流:

So far so good, but the trick is inside the method, where you have to 'manually' initialize the desired flow by doing the following:

public String initFlow(){
   FacesContext context = FacesContext.getCurrentInstance();
   FlowHandler handler = context.getApplication().getFlowHandler();
   handler.transition(context, null, handler.getFlow(context, "", "flow-name"), null, "");
   return "flow-name";
}

transition方法激活"命名的流程并使之可用,以便随后可以转发到该流程的入口点.
请注意,即使它看起来像是普通转发,viewAction总是进行重定向!

The transition method 'activates' the named flow and makes it available, so that you then can forward to the entry point of the flow.
Please note, that even if it looks like a normal forward, viewAction always does a redirect!

这篇关于可以从Servlet内部启动人脸流吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆