如何使用JSF2获取GET参数? [英] How get GET parameters with JSF2?
问题描述
我有这样的网址:
http://example.com?parameter=content
当用户点击此链接时,我应该能够获得内容的参数值。
我读的是BalusC 教程,但是JSF 1.2和I' m学习JSF 2.
我怎么能这样做?
有两种方法(这两个例子都假设参数名称是参数
在你的问题中):
-
使用
@ManagedProperty
关于所需的bean属性:@ManagedProperty(#{param.parameter})
private String参数;
这仅适用于请求作用域bean,并且不允许进行细粒度转换和验证。
-
使用
< f:viewParam>
:
< f:元数据>
< f:viewParam name =parametervalue =#{bean.parameter}/>
< / f:元数据>
这也适用于视图范围的bean,并允许使用标准验证器进行细粒度转换和验证就像正常的输入组件一样。它甚至可以附加
< h:message>
。
另见:
- JSF 2.0中的通信 - 处理GET请求参数
- ViewParam vs @ManagedProperty(value ="#{param.id}")
Use
@ManagedProperty
on the desired bean property:@ManagedProperty("#{param.parameter}") private String parameter;
This works on request scoped beans only and does not allow for fine grained conversion and validation.
Use
<f:viewParam>
in the view pointing to the desired bean property:<f:metadata> <f:viewParam name="parameter" value="#{bean.parameter}" /> </f:metadata>
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>
.- Communication in JSF 2.0 - Processing GET request parameters
- ViewParam vs @ManagedProperty(value = "#{param.id}")
ul>
I have this url for example:
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.
How could I do that?
Two ways (both examples assume that the parameter name is parameter
as in your question):
See also:
这篇关于如何使用JSF2获取GET参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!