Prototype of page actions available in Seam 3

Posted by    |       Seam

Before I start, I want to mention that Seam 3 is extremely green right now. The main motivation for jumping into now is to work out the kinks in the JSR-299 and JSF 2 implementations. Plus, I'm starting to get the word out about what's going on with Seam 3 so that you can help drive its future and be a part of the process.

If you've read anything I've written about Seam, you know that I am a huge fan of page actions. Not because I disagree with the event-driven style of a component model, but rather because the web is diverse (and likely your intranet as well). Often times, the only way you can get an application to work properly is to sprinkle a page action here in there. PLUS, it's essential for view-level security and the enforcement of other prerequisites.

With that said, I have completed a prototype of page actions in Seam 3. Only now, we are calling them view actions. The reason for the name change is because the JSF EG renamed Red Hat's page parameter contribution to view parameters. So, we are bring page actions inline with the terminology settled on by the EG. We are hopeful view actions will make it into JSF 2.1.

Okay, so why the big announcement? View actions are interesting because they blend two very cool features in JSF 2. First, the view action is defined in the new metadata facet. This facet is a non-rendered region of the component tree that can host components which describe how the page should be processed. One example of metadata is a view action. The second feature is the PreRenderViewEvent, which is really what give view actions life. This event is fired right before the view is rendered. If the view ID is changed by a listener, the event is fired again. But that leaves it up to us to actually weave in the navigation handling.

So instead of using pages.xml, you will now define page actions in your view template (and be able to leverage Facelets templating to share common definitions across pages)

<f:metadata>
   <s:viewAction execute="#{blog.loadEntry}"/>
</f:metadata>

The view actions work almost identically as they do in Seam 2. If a navigation case is matched, it short-circuits the execution of all subsequent view actions. View actions only execute on an initial request by default. You can have them execute for every request using onPostback="true". You can also supply a condition to control if the action is executed contextually (e.g., if="#{facesContext.validationFailed}).

I have also implemented a rough prototype of view-level security:

<s:restrictView required="#{identity.loggedIn}"/>

You may also be interested in how I implemented these two features. I setup a processor chain so:

  1. It's easy to add additional behavior before the view is rendered
  2. So each processor can be implemented as a JSR-299 bean and take advantage of contextual injection

Check it out. Give us feedback. You can see these components in action in the Seam 3 booking example and permalink examples.


Back to top