10

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Valter Silva
  • 16,446
  • 52
  • 137
  • 218

2 Answers2

23

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • thanks mate, it works fine. I use the second approach, it think it was more simple. I'm really enjoying JSF, it's really nice. =] – Valter Silva Oct 15 '11 at 12:59
0

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

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

Sunil
  • 127
  • 4
  • 11