[seam-dev] Replacing pages.xml

Stuart Douglas stuart at baileyroberts.com.au
Thu Feb 18 23:58:39 EST 2010

I have been thinking about the replacement for pages.xml. Even though JSF2 has made some aspects of pages.xml redundant, pages.xml is still important as it allows you to apply actions/security setting etc to a large number of pages at once using wildcards. With that said however it would be nice to move to a design that is more typesafe and extensible. I have come up with a preliminary idea of how this might work, I will explain with an example:

public @Interface SecurityConfig
   boolean loginRequired();
   String restrict();

 * This bean will only be considered for injection when the context path is
 * /app/restricted/*, and it is the most specific page available.
public class RestrictedArea extends Page


This may also be configured via XML using seam-xml.
There is nothing special about the page class, it is an empty class
that is provided solely to be configured with annotations:

  <SecurityConfig loginRequired="true" />

The application can get access to this information in a number of ways:

@Inject PageDataProvider<SecurityConfig> data;

public void doStuff()
  //get the most specific result
  SecurityConfig security = data.get();

  //get all applicable results
  List<SecurityConfig> secinfo = data.getAll();

  //secinfo is ordered from most to least specific,
  //secinfo.get(0) will be equal to data.get()


Alternatively the most specific result can be injected directly:

@Inject SecurityConfig data;

We could also support an event based approach:

public void pageEvent(@Observes @Rendered("/secure/*") Page page, SecurityConfig config)
  //do stuff

Does this sound like a good approach? I am fairly sure all this can be implemented as a portable extension. 

More information about the seam-dev mailing list