Details
-
Type:
Feature Request
-
Status: Open (View Workflow)
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: 3.1.0.Tracking
-
Component/s: View Configuration
-
Labels:None
-
Forum Reference:
Description
Be able to configure a page action with ViewConfig.
For instance :
|
@ViewConfig
|
public interface Pages { |
static enum Pages1 { |
|
|
@ViewPattern("/*") |
@ViewAction("#{bean.doSomething()}") |
ALL;
|
}
|
|
|
}
|
Prettyfaces can be a source of inspiration since it has this capability, and the added bonus of specifying which phase you want this to occur.
The easy way out is to use EL to bind actions to view config enums:
@ViewConfigpublic interface ApplicationViewConfig {static enum Views {@ViewAction("#{bean.loadItem}")VIEW_ITEM}}However, that requires all sorts of named beans and it's just pretty off base from what CDI is all about.
A far better solution is to use binding annotations, just like qualifiers and interceptor bindings from CDI and security bindings from Seam Faces.
To make this as strongly typed as possible, we want to allow the developer to refer to the view config in the value attribute of the binding annotation. Thus, they first define the binding:
@ViewActionBindingType@Retention(RUNTIME)@Target(ElementType.METHOD)public @interface ViewAction {Views[] value();}Then, they annotate the method they want to call.
@ViewAction(VIEW_ITEM)public void loadItem() {...}The best part is, that method can have injected arguments. The injected argument could be a bean populated by a PrettyFaces mapping, viewParam or a converted request parameter (provided by Seam Servlet):
@ViewAction(VIEW_ITEM)public void loadItem(@Selected Item item) {...}or
@ViewAction(VIEW_ITEM)public void loadItem(@RequestParam("id") Long id) {...}If you needed the action for view and edit, you just do:
@ViewAction({VIEW_ITEM, EDIT_ITEM})public void loadItem(@RequestParam("id") Long id) {...}We should also allow view actions to be nested:
The only part that sucks is that the user has to create the @ViewAction annotation so that it's linked to the view config enum (stupid Java). We could recommend adding this annotation as part of the view config class file (or even have tooling generate it).