I have a JSP page this contains a form with method "post" and in the action it calls a page xhtml in jsf 2.2. How can I make for retrieve inside my xhtml page the post fields send from my jsp page. Thanks.
2 Answers
You can (ab)use <f:viewParam>
for this.
Imagine this "plain HTML" form (JSP is irrelevant as it's just the HTML code producer here; it can as good be any server side language/framework/viewtechnology):
<form action="some.xhtml" method="post">
<input type="text" name="foo" />
<input type="text" name="bar" />
<input type="submit" />
</form>
You can collect and set the inputs as JSF bean properties and invoke a bean action as below:
<f:metadata>
<f:viewParam name="foo" value="#{bean.foo}" />
<f:viewParam name="bar" value="#{bean.bar}" />
<f:viewAction action="#{bean.action}" onPostback="true" />
</f:metadata>
Note the importance of onPostback="true"
, by default this is namely invoked on GET only. The <f:viewParam>
initially also, but it will fill the model anyway if it turns out to be null.
If you actually don't need those parameters in the model (the backing bean), then you can also just access them right away via #{param}
map in JSF page:
<p>User submitted data:</p>
<ul>
<li>Foo: #{param.foo}</li>
<li>Bar: #{param.bar}</li>
</ul>
On long term, better is to turn that legacy JSP page into a real JSF page.
See also:
I think your form UI in JSP page and you want to access form data in xhtml page. If you want to access parameter value in xhtml file :
In JSP:
<form action="" method="">
<input name="myName" type="text">
<input value="Submit" type="Submit">
</form>
In XHTML :
To access 'myName' parameter in xhtml page please use like following
eg. <h:outputLabel value="#{request.getParameter('myName')}"/>

- 2,916
- 1
- 29
- 33