0

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

1 Answers1

0

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?

Community
  • 1
  • 1
Elias Dorneles
  • 22,556
  • 11
  • 85
  • 107
  • Thanks for your reply. With "static" parameters everything works fine, but I would like to have something similar to ` – user1563703 Jul 30 '12 at 20:04
  • EL is valid there too, so you can use something like `#{param.field1}`. Check out [EL implicit objects](http://developers.sun.com/docs/jscreator/help/2update1/jsp-jsfel/jsf_expression_language_intro.html#implicitobjects). – Elias Dorneles Jul 30 '12 at 21:34
  • The problem is that only the "initial" values of the form are sent. If I modify fields, the changes are not sent. I guess there is some trick to do, since the form uses a POST method (maybe POST/Redirect/GET) but I don't know how to do that. – user1563703 Jul 30 '12 at 21:40
  • Ah, I think I understood, what you want is a plain HTML form with method="get", see [the second part of this answer](http://stackoverflow.com/a/4823289/149872). If you just want to submit the same values, why not just use POST with an `h:commandButton` instead? – Elias Dorneles Jul 30 '12 at 22:21
  • I finally understood what was my problem. I tried a commandButton with "faces-redirect=true&includeViewParams=true" (in A.xhtml) which didn't add any GET parameters. It was simply that in B.xhtml, I had to refer (with viewParam) to "A" bean fields (I used f:viewParam value="#{B.field1}" instead of f:viewParam value="#{A.field1}" – user1563703 Jul 31 '12 at 12:41
  • yeah, if you only go to B from A, that will work. glad you solved it! – Elias Dorneles Jul 31 '12 at 13:05