Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>If you are not submitting a form by going from one page to the next, then what are you doing?</p> </blockquote> <p>Navigating to another page without submitting any form fields.</p> <blockquote> <p>My app involves entering information in a form, hitting a button and then going to a new page that displays results after running a query. It seems I have seen this activity take place with s:button</p> </blockquote> <p>s:button won't submit the form, so the values on your page will not be applied to the model. You must use a commandButton/Link for this. The activity you may have seen is passing an already populated value to another page. </p> <h2>f:param</h2> <p>Used more often with s:button/link as these are often used for navigation. You can use f:param to pass an already populated value across to another page. h:commandButton/Link is used for submitting forms so the values are in form fields. Of course there is nothing stopping you from using f:param for this to.</p> <h2>page.xml</h2> <p>the params used here are for applying request parameters to the model and vice versa. </p> <h2>@RequestParameter</h2> <p>Can be used in conjunction with all of the above but is a little pointless when used with page.xml params as they can be used to do the same job</p> <h2>Example</h2> <p>If you start with this page: </p> <pre><code>http://mydomain.com/myapp/home.seam?name=damo </code></pre> <p>And the home.page.xml has:</p> <pre><code>&lt;param name="name" value="#{person.name}"/&gt; </code></pre> <p>Then when the page is loaded <code>person.setName("damo")</code> will be called as there is a matching request parameter in the URL.</p> <p>You can store the value of the param in the link to the next page:</p> <pre><code>&lt;s:link value="Go to Page 2" view="/page2.xhtml"&gt; &lt;f:param name="name" value="#{person.name}"/&gt; &lt;/s:link&gt; </code></pre> <p>When you click the link and navigate to <a href="http://mydomain.com/myapp/page2.seam" rel="noreferrer">http://mydomain.com/myapp/page2.seam</a> And the page2.page.xml has:</p> <pre><code>&lt;param name="name" value="#{someOtherBean.name}"/&gt; </code></pre> <p>Then <code>someOtherBean.setName("damo")</code> will be called.</p> <p>Page2 may have a s:button like this:</p> <pre><code>&lt;s:button value="Say Hello" action="#{someOtherBean.sayHello}"&gt; &lt;f:param name="subject" value="#{someOtherBean.name}"/&gt; &lt;/s:button&gt; </code></pre> <p>And the method could be:</p> <pre><code>@Name("someOtherBean") public class SomeOtherBean { @RequestParameter("subject") //same value as the 'name' in f:param private String subject; public void sayHello() { System.out.println("Hello "+subject); } } </code></pre> <p>Hope this helps!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload