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

查看:20
本文介绍了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 页面读取这些参数(例如,如此处) 并调用支持 bean 业务方法,而无需向用户浏览器呈现任何内容
  3. 用户被透明地发送到与步骤 2 中调用的支持 bean 方法的导航结果相对应的页面.
  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.

换句话说,步骤2PrimeFaces页面只涉及调用backing-bean业务方法和从不显示.用户在点击步骤 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.

推荐答案

使用 将 GET 参数设置为 bean 属性并使用 执行一个bean动作并使用 NavigationHandler 以编程方式执行导航.

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>

豆子:

public void action() {
    // ...

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

请注意,根据具体的功能需求,JSF 可能不一定是适合该工作的工具.我会调查您是否不能更好地使用 servlet 过滤器,甚至是普通的 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.

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

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