How get GET parameters with JSF2? [duplicate]

旧街凉风 提交于 2019-12-28 15:21:45

问题


I have this url for example:

http://example.com?parameter=content

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?


回答1:


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

  1. 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.

  2. 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>.

See also:

  • Communication in JSF 2.0 - Processing GET request parameters
  • ViewParam vs @ManagedProperty(value = "#{param.id}")



回答2:


Use tag "<f:view ( View Parameters ) to bind to bean and get the parameter

Also u can inject the parameters using #{param.content}



来源:https://stackoverflow.com/questions/7775179/how-get-get-parameters-with-jsf2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!