33import java .lang .reflect .Method ;
44
55import javax .faces .context .FacesContext ;
6- import javax .faces .event .PhaseId ;
76
8- import org .ocpsoft .prettyfaces .annotation .AfterPhase ;
9- import org .ocpsoft .prettyfaces .annotation .BeforePhase ;
7+ import org .ocpsoft .common .util .Assert ;
108import org .ocpsoft .prettyfaces .annotation .RequestAction ;
119import org .ocpsoft .rewrite .annotation .api .HandlerChain ;
1210import org .ocpsoft .rewrite .annotation .api .MethodContext ;
1614import org .ocpsoft .rewrite .context .EvaluationContext ;
1715import org .ocpsoft .rewrite .el .El ;
1816import org .ocpsoft .rewrite .event .Rewrite ;
19- import org .ocpsoft .rewrite .faces .config .PhaseAction ;
20- import org .ocpsoft .rewrite .faces .config .PhaseOperation ;
2117
2218public class RequestActionHandler extends MethodAnnotationHandler <RequestAction >
2319{
@@ -40,39 +36,16 @@ public void process(MethodContext context, RequestAction annotation, HandlerChai
4036
4137 // create Operation for executing this method
4238 Method method = context .getJavaMethod ();
43- Operation invocation = Invoke .binding (El .retrievalMethod (method ));
39+ Operation rawOperation = Invoke .binding (El .retrievalMethod (method ));
4440
45- // wrap the operation if it shouldn't be executed on postbacks
46- if (!annotation .onPostback ()) {
47- invocation = new IgnorePostbackOperation (invocation );
48- }
49-
50- // the action invocation must be deferred to get executed inside the JSF lifecycle
51- PhaseOperation <?> deferredOperation = PhaseAction .enqueue (invocation );
52-
53- // queue the operation for a specific time in the JSF lifecycle
54- BeforePhase beforePhase = method .getAnnotation (BeforePhase .class );
55- AfterPhase afterPhase = method .getAnnotation (AfterPhase .class );
56- if (beforePhase == null && afterPhase == null ) {
57- deferredOperation .after (PhaseId .RESTORE_VIEW );
58- }
59- else if (beforePhase == null && afterPhase != null ) {
60- deferredOperation .after (afterPhase .value ().getPhaseId ());
61- }
62- else if (beforePhase != null && afterPhase == null ) {
63- deferredOperation .before (beforePhase .value ().getPhaseId ());
64- }
65- else {
66- throw new IllegalStateException ("Error processing @" + handles ().getSimpleName () + " annotation on method "
67- + method .getDeclaringClass ().getName () + "#" + method .getName ()
68- + ": You cannot use @" + BeforePhase .class .getSimpleName () + " and @"
69- + AfterPhase .class .getSimpleName () + " at the same time." );
70- }
41+ // let subsequent handlers enrich the operation
42+ context .put (Operation .class , rawOperation );
43+ chain .proceed (context );
44+ Operation enrichedOperation = (Operation ) context .get (Operation .class );
45+ Assert .notNull (enrichedOperation , "Operation was removed from context" );
7146
7247 // append this operation to the rule
73- context .getRuleBuilder ().perform (deferredOperation );
74-
75- chain .proceed (context );
48+ context .getRuleBuilder ().perform (enrichedOperation );
7649
7750 }
7851
0 commit comments