9.3. Starting conversations with GET requests
JSF does not define action listeners triggered when a page is accessed through a non-Faces request (for example, an HTTP GET request). This can occur when a user bookmarks the page, or navigates to the page through
<h:outputLink>.
Sometimes you want a conversation to begin immediately when a page is accessed. As there is no JSF action method, you cannot annotate the action with
@Begin.
Further problems arise when the page requires state to be fetched into a context variable. You have seen two methods of solving this problem. If the state is held in a Seam component, you can fetch the state in a
@Create method. If not, you can define a @Factory method for the context variable.
If neither option works for you, Seam allows you to define a page action in the
pages.xml file.
<pages> <page view-id="/messageList.xhtml" action="#{messageManager.list}"/> ... </pages>
This action method is called at the beginning of the render response phase — that is, any time the page is about to be rendered. If a page action returns a non-null outcome, Seam processes appropriate JSF and Seam navigation rules. This can result in a completely different page rendering.
If beginning a conversation is all you want to do before rendering the page, you can use a built-in action method:
<pages> <page view-id="/messageList.xhtml" action="#{conversation.begin}"/> ... </pages>
You can also call this built-in action from a JSF control, and
#{conversation.end} similarly ends conversations.
You can use the
<begin-conversation> element for further control over joining existing conversations, or beginning a nested conversation or an atomic conversation; as follows:
<pages> <page view-id="/messageList.xhtml"> <begin-conversation nested="true" /> <page> ... </pages>
There is also a
<end-conversation> element.
<pages> <page view-id="/home.xhtml"> <end-conversation/> <page> ... </pages>
You have five options to begin a conversation immediately when a page is accessed:
- Annotate the
@Createmethod with@Begin - Annotate the
@Factorymethod with@Begin - Annotate the Seam page action method with
@Begin - Use
<begin-conversation>inpages.xml - Use
#{conversation.begin}as the Seam page action method