如何使用 JSF2 获取 GET 参数? [英] How get GET parameters with JSF2?

查看:20
本文介绍了如何使用 JSF2 获取 GET 参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我有这个网址:

http://example.com?parameter=content

当用户单击此链接时,我应该能够获得内容"的参数值.我正在阅读 BalusC 教程但是是 JSF 1.2,我正在学习 JSF2.

When the user click in this link, then I should be able to get the parameter value which is 'content'. I was reading BalusC tutorial but is JSF 1.2 and I'm learning with JSF 2.

我怎么能这样做?

推荐答案

两种方式(两个示例都假设参数名称是您的问题中的 parameter):

Two ways (both examples assume that the parameter name is parameter as in your question):

  1. 使用@ManagedProperty 在所需的 bean 属性上:

  1. Use @ManagedProperty on the desired bean property:

@ManagedProperty("#{param.parameter}")
private String parameter;

这仅适用于请求范围的 bean,不允许细粒度的转换和验证.

This works on request scoped beans only and does not allow for fine grained conversion and validation.

使用 在视图中指向所需的 bean 属性:

Use <f:viewParam> in the view pointing to the desired bean property:

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

这也适用于视图范围的 bean,并允许使用标准验证器进行细粒度转换和验证,就像在普通输入组件上一样.它甚至允许附加 .

This works on view scoped beans as well and allows for fine grained conversion and validation using the standard validators like as on normal input components. It even allows for attaching a <h:message>.

另见:

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