-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Seamfaces 147 - viewActions #64
base: develop
Are you sure you want to change the base?
Conversation
ViewAction are registered in ViewConfigStore. Limitation due to ViewConfigStore storing only Annotation. I need to store at least AnnotatedMethod otherwise I won't be able to know which method to call if 2 methods have been annotated with exactly the same annotation (same attribute values I think).
@ViewAction and @ViewActionBindingType usage are as per https://issues.jboss.org/browse/SEAMFACES-147 @ViewController usage is like MyFaces CODI's @PageBean (https://cwiki.apache.org/confluence/display/EXTCDI/JSF+Usage#JSFUsage-PageBeans) Sample usage in seam-faces-example-viewconfig application
Those where shortcut annotations duplicating @Before/@after @RenderResponse
And removed usage of @Before/@after and phase annotation with @ViewAction. Attribute usage is more explicit here.
Hello, Thought a bit about the bugs and code redundancy part. I had an idea but it would require a bit of refactoring. Here's the idea :
ViewActionHandler will represents all actions executed during the view processing lifecycle. ViewAction will contain :
There will be 3 implementations of ViewActionHandler. One of them will be itself generic - a la Hibernate Validator. First one : SecurityBindingTypeHandlerThis will execute a code similar to the actual SecurityPhaseListener. With this handler there will be a SecurityBindingTypeExtension which will scan all SecurityBindingType annotations and add them to the corresponding ViewConfig#viewActionHandlers. Second one : ViewActionBindingTypeHandlerSame thing but for ViewActionBinding annotations. Third one : ViewActionHandler - a la Hibernate ValidatorFor this one, we need an additional interface : ViewActionHandlerProvider, and an additionnal meta-annotation @ViewAction. public interface ViewActionHandlerProvider<V extends ViewAction> {
List<ViewActionHandler> getActionHandlers();
void initialize(X annotation);
} There will be one viewActionHandlerProvider per annotation (with a ViewAction binding type annotation) appearing on a view enum. Sample usage : creating a @BeginConversation view action. @ViewConfig
public interface MyAppViewConfig {
static enum Pages {
@ViewPattern("/item.xhtml")
@BeginConversation
ITEM
} @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@ViewAction(BeginConversationHandler.class)
@Begin @ApplyRequestValues
public @interface BeginConversation {
} public class BeginConversationHandler implements ViewActionHandler<ElViewAction> {
@Inject
private Conversation conversation;
boolean handles(PhaseInstant phaseInstant) {...}
void initialize(ElViewAction annotation) {...}
public Object execute() {
conversation.begin();
return null;
}
} And with a similar logic, we have our ElViewAction (donno how to better name all these interfaces / classes) What's next ?My implementation notes are available here : https://gist.github.com/1356107 If you're interested by this approach I can work on it the next or the following week and make another pull request. |
viewAction functionnality in 3 flavors :
@viewconfig
public interface ApplicationViewConfig {
static enum View1 {
@ViewPattern("/item.xhtml")
@ViewAction("#{bean.doSomething()}")
VIEW_ITEM;
}
}
@viewconfig
public interface ApplicationViewConfig {
static enum View1 {
@ViewPattern("/item.xhtml")
VIEW_ITEM;
}
}
public class ItemAction {
@ViewAction(VIEW_ITEM)
public void loadItem() {
...
}
}
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 :
This annotation would be called before a JSF action (whether immediate or not).
Not 100% sure about its usefulness though.
Bugs / code redundancy :