0

I use,

  • Java EE 7
  • Payara 4.1.1
  • JSF 2.2
  • RichFaces 4.5.15
  • PrimeFaces 6.0.

If I have this URL: mysite.com/mypage.jsf?field1=value1&field2=value2

I would like that, when the user typed this URL, I opened the mypage.jsf with fields 1 and 2 filled with value1 and value2.

  • <inputText id="field1" value="HOWTOGETFROMURL-value1"/>
  • <inputText id="field2" value="HOWTOGETFROMURL-value2"/>
Tiny
  • 27,221
  • 105
  • 339
  • 599

1 Answers1

1

The way to catch any parameter from the url is to use metadata and viewParam tags in the head of the page in the url.

So in your mypage.jsf, the tags will be :

<h:head>
....
<f:metadata>
    <f:viewParam name="field1" value="#{yourManagedBean.field1}"/>
    <f:viewParam name="field2" value="#{yourManagedBean.field2}"/>
</f:metadata>
</h:head>

Your managed bean must have attributes to receive the values from Url.

and the inputs will be :

<h:inputText id="field1" value="#{yourManagedBean.field1}"/>
<h:inputText id="field2" value="#{yourManagedBean.field2}"/>

I hope it helps.

Sam
  • 605
  • 9
  • 19