如何在页面加载时在后备bean中处理GET查询字符串URL参数? [英] How do I process GET query string URL parameters in backing bean on page load?

查看:104
本文介绍了如何在页面加载时在后备bean中处理GET查询字符串URL参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了如何使用JSF发送参数,但是如果用户在访问登录页面时在URL中键入其companyId怎么办?例如

I've read how to send parameters using JSF but what if the user types their companyId in the URL when accessing their login page? For example,

http://my.company.url/productName/login.faces? companyId = acme .

我们现在的方式是,有一些scriptlet代码从请求中获取值,然后在会话中进行设置.从登录页面开始,该参数会改变其外观,因此每个客户都可以拥有不同的登录页面视图.在我切换到JSF之前,我们一直在使用extjs.

The way we do it now, there is a bit of scriptlet code that grabs the value from the request and then set it in the session. That parameter changes their look and feel starting from the login page forward so each customer could have a different login page view. We are using extjs until I switch over to JSF.

是否可以使用JSF 2或PrimeFaces来做到这一点?

Is there a way to do that using JSF 2 or perhaps PrimeFaces?

推荐答案

是的,您可以使用

Yes, you can use the <f:viewParam> to set a request parameter as a managed bean property.

<f:metadata>
    <f:viewParam name="companyId" value="#{bean.companyId}" />
</f:metadata>

如有必要,您可以使用<f:viewAction>(仅JSF 2.2+)或<f:event type="preRenderView">调用bean操作.

You can if necessary invoke a bean action using <f:viewAction> (JSF 2.2+ only) or <f:event type="preRenderView">.

<f:metadata>
    <f:viewParam name="companyId" value="#{bean.companyId}" />
    <f:viewAction action="#{bean.onload}" />
</f:metadata>

使用<f:viewAction>时,您甚至可以返回导航结果.

When using <f:viewAction> you can even return a navigation outcome.

public String onload() {
    // ...

    return "somepage";
}

如果尚未使用JSF 2.2,则可以使用 ExternalContext#redirect() .另请参见如何在preRenderView侦听器方法中执行导航

When not on JSF 2.2 yet, you can use ExternalContext#redirect() for that. See also among others How to perform navigation in preRenderView listener method.

请注意,这并非特定于PrimeFaces.它只是标准JSF的一部分. PrimeFaces仅仅是一个组件库,它提供了增强的Ajax和可换肤性支持.

Note that this is not specific to PrimeFaces. It's just part of standard JSF. PrimeFaces is merely a component library which provides enhanced ajax and skinnability support.

  • What can <f:metadata>, <f:viewParam> and <f:viewAction> be used for?
  • Communication in JSF 2.0 - Processing GET request parameters

这篇关于如何在页面加载时在后备bean中处理GET查询字符串URL参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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