简体   繁体   中英

Using GET parameters in JSF2

I'm trying to pass form field values as GET parameters between 2 views (called "A" and "B"). In "B", I handle the parameters with f:metadata and f:viewParam. This part works great if I use the URL directly.

However, now I would like to pass fields from another view "A", but currenly without success. The fields are defined as follows:

<h:form>
<p:inputText id="field1" value="#{A.field1}"/>
<p:inputText id="field2" value="#{A.field2}"/>
[...]
</h:form>

If I use f:param within a Primefaces p:button, the parameters are transmitted but not retrieved dynamically (in fact, if I check the web page html code, the initial values of the form are written "statically").

What is the best approach to handle this ?

Thanks in advance

Use h:button with f:param :

<h:button outcome="B.xhtml" value="Click me!">
    <f:param name="maybe_an_id" value="3" />
</h:button>

This will generate a normal HTML button, with a Javascript on click like this:

<input type="button" value="Click me!"
  onclick="window.location.href='/path/to/B.xhtml?maybe_an_id=3'; return false;">

See also: When should I use h:outputLink instead of h:commandLink?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM