JSF:调用backing-bean方法而不呈现页面(使用URL参数) [英] JSF: call backing-bean method without rendering the page (using URL parameters)

查看:123
本文介绍了JSF:调用backing-bean方法而不呈现页面(使用URL参数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过以下方式使用 JSF (PrimeFaces)页面? :

Is it possible to use a JSF (PrimeFaces) page in the following fashion ? :

  1. 外部应用程序(不是基于 JSF 的)使用 URL 参数执行 HTTP GET
  2. JSF 页面读取这些参数(例如,如
  1. external application (not JSF-based) does an HTTP GET with URL parameters
  2. JSF page reads those parameters (e.g. as described here) and invokes a backing bean business method, without rendering anything to the user's browser
  3. The user is transparently sent to a page corresponding to the navigation outcome of the backing bean method invoked in step 2.

换句话说,步骤 2 PrimeFaces 页面仅涉及调用后备豆业务方法的副作用,并且永远不会显示.单击步骤 1 的外部应用程序上的链接后,用户将进入步骤 3 的页面.

In other words, the PrimeFaces page of step 2 is involved only for the side effect of calling the backing-bean business method and is never displayed. The user after clicking on a link on the external application of step 1 lands in the page of step 3.

推荐答案

使用

Use <f:viewParam> to set GET parameters as bean properties and use <f:event> to execute a bean action and use NavigationHandler to perform navigation programmatically.

查看:

<f:metadata>
    <f:viewParam name="foo" value="#{bean.foo}" />
    <f:viewParam name="bar" value="#{bean.bar}" />
    <f:event type="preRenderView" listener="#{bean.action}" />
</f:metadata>

Bean:

public void action() {
    // ...

    FacesContext context = FacesContext.getCurrentInstance();
    NavigationHandler navigationHandler = context.getApplication().getNavigationHandler();
    navigationHandler.handleNavigation(context, null, "outcome");
}

请注意,根据具体的功能要求,JSF不一定是适合该工作的工具.我会调查您是否最好使用 servlet过滤器甚至是普通的

Note that, depending on the concrete functional requirement, JSF might not necessarily be the right tool for the job. I'd investigate if you couldn't better use a servlet filter or even a plain servlet for the purpose.

  • What can <f:metadata>, <f:viewParam> and <f:viewAction> be used for?
  • Hit a bean method and redirect on a GET request

这篇关于JSF:调用backing-bean方法而不呈现页面(使用URL参数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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