As I debug my seam application, it dawns on me that I don't really understand how parameter passing works. The following terminology really has me confused. So I am asking this very general question in the hopes of getting a good explanation of what works with what and what certain things are for.
First of all, to get from one page to the next you can use h:commandButton or s:button. I understand that s:button does not submit a form, but that doesn't help me understand the difference. If you are not submitting a form by going from one page to the next, then what are you doing?
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, so how is that if it's not "submitting a form"? I feel I'm missing something fundamental here.
As for the parameters themselves...from what I have seen you can pass parameters using one of 3 methods:
I'm sure this question reveals a great deal of ignorance.
Hopefully one of you eloquent people will "get" what I'm asking and give me an explanation of this process.
Thanks in advance.
TDR
If you are not submitting a form by going from one page to the next, then what are you doing?
Navigating to another page without submitting any form fields.
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
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.
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.
the params used here are for applying request parameters to the model and vice versa.
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
If you start with this page:
http://mydomain.com/myapp/home.seam?name=damo
And the home.page.xml has:
<param name="name" value="#{person.name}"/>
Then when the page is loaded person.setName("damo")
will be called as there is a matching request parameter in the URL.
You can store the value of the param in the link to the next page:
<s:link value="Go to Page 2" view="/page2.xhtml">
<f:param name="name" value="#{person.name}"/>
</s:link>
When you click the link and navigate to http://mydomain.com/myapp/page2.seam And the page2.page.xml has:
<param name="name" value="#{someOtherBean.name}"/>
Then someOtherBean.setName("damo")
will be called.
Page2 may have a s:button like this:
<s:button value="Say Hello" action="#{someOtherBean.sayHello}">
<f:param name="subject" value="#{someOtherBean.name}"/>
</s:button>
And the method could be:
@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);
}
}
Hope this helps!