-
1. Re: JSF action versus seam page action
cash1981 Jul 27, 2009 6:31 PM (in response to daxxy)You should definetly don't do like that.
Read the Seam pageflow
Basically what you can do is have a method that returns a string, and based on that string you can navigate to whatever page you want. You write that in your page.xml file or pages.xml.
For instances:
<page view-id="/numberGuess.jsp"> <navigation> <rule if-outcome="guess"> <redirect view-id="/numberGuess.jsp"/> </rule> <rule if-outcome="win"> <redirect view-id="/win.jsp"/> </rule> <rule if-outcome="lose"> <redirect view-id="/lose.jsp"/> </rule> </navigation> </page>
public String guess() { if (guess==randomNumber) return "/win.jsp"; if (++guessCount==maxGuesses) return "/lose.jsp"; return null; }
-
2. Re: JSF action versus seam page action
asookazian Jul 27, 2009 7:17 PM (in response to daxxy)If you don't need to set a value in a Seam component via pages.xml (or via injection, for example), then the example above (returning
/foo.xhtml
from an action method) will work well strictly for navigation purposes.But to answer your question:
How do I put an action into the page.xml and get it to use a parameter from that file?
You have a couple of options that I'm aware of. One is using page params and the other is @RequestParameter to inject the value into your Seam component.
An example I just looked at that works for the page param approach is in the seamdvd example project.
pages.xml:
<page view-id="/dvd.xhtml" action="#{search.selectFromRequest}"> <param name="id" value="#{search.selectedId}"/> <navigation from-action="#{search.addToCart}"> <redirect view-id="/dvd.xhtml"/> </navigation> </page>
I added a breakpoint here:
@Stateful @Name("search") public class FullTextSearchAction implements FullTextSearch, Serializable {... public void setSelectedId(Long id) { this.id = id; //this line is executed! } }
key point: setter is called prior to action method execution.
HTH