seam/faces — pull request #64 by gonzalad (2011-11-03 22:44:33+00:00)
Title: Seamfaces 147 - viewActions

viewAction functionnality in 3 flavors :

1. Untyped approach (not so CDI like - but dead simple and similar to Seam 2 pages.xml)
@ViewConfig
public interface ApplicationViewConfig {
static enum View1 {
@ViewPattern("/item.xhtml")
@ViewAction("#{bean.doSomething()}")
VIEW_ITEM;
}
}

2. Typed - you just need to create your own annotation with @ViewActionBindingTypeQualifier with value pointing to the view enum.
@ViewConfig
public interface ApplicationViewConfig {
static enum View1 {
@ViewPattern("/item.xhtml")
VIEW_ITEM;
}
}

public class ItemAction {
@ViewAction(VIEW_ITEM)
public void loadItem() {
...
}
}

3. Page Controller
Just annotate your view enum with a @Controller pointing to a CDI managed-bean.
The managed bean lifecycle methods will automatically be called during this view lifecycle.
@ViewConfig
public interface ApplicationViewConfig {
static enum View1 {
@ViewPattern("/item.xhtml")
@Controller(ItemController.class)
VIEW_ITEM;
}
}
public class ItemController {
@Before
@RenderResponse
public void loadItem() {
...
}
}

Unit tests and sample application provided.

Functionnality missing in my opinion :
* Introducing @BeforeAction
This annotation would be called before a JSF action (whether immediate or not).
Not 100% sure about its usefulness though.

Bugs / code redundancy :
* enforce order execution between Restrict annotation and view actions (pb is CDI events aren't ordered).
* don't like xxxPhase dependency on xxxExtension, should be the other way around
* findViewsWithPatternsThatMatch and qualifier resolution logic duplicated in ViewConfigStoreImpl and ViewControllerStore (extract into common utility ?)