|
3 | 3 | import java.lang.reflect.Method; |
4 | 4 |
|
5 | 5 | import javax.faces.context.FacesContext; |
| 6 | +import javax.faces.event.PhaseId; |
6 | 7 |
|
7 | | -import org.ocpsoft.prettyfaces.annotation.Phase; |
| 8 | +import org.ocpsoft.prettyfaces.annotation.AfterPhase; |
| 9 | +import org.ocpsoft.prettyfaces.annotation.BeforePhase; |
8 | 10 | import org.ocpsoft.prettyfaces.annotation.URLAction; |
9 | 11 | import org.ocpsoft.rewrite.annotation.api.MethodContext; |
10 | 12 | import org.ocpsoft.rewrite.annotation.spi.MethodAnnotationHandler; |
@@ -39,21 +41,24 @@ public void process(MethodContext context, Method method, URLAction annotation) |
39 | 41 |
|
40 | 42 | // the action invocation must be deferred to get executed inside the JSF lifecycle |
41 | 43 | PhaseOperation<?> deferredOperation = PhaseAction.enqueue(invocation); |
42 | | - |
| 44 | + |
43 | 45 | // queue the operation for a specific time in the JSF lifecycle |
44 | | - if (annotation.after() == Phase.NONE && annotation.before() == Phase.NONE) { |
45 | | - deferredOperation.after(javax.faces.event.PhaseId.RESTORE_VIEW); |
| 46 | + BeforePhase beforePhase = method.getAnnotation(BeforePhase.class); |
| 47 | + AfterPhase afterPhase = method.getAnnotation(AfterPhase.class); |
| 48 | + if (beforePhase == null && afterPhase == null) { |
| 49 | + deferredOperation.after(PhaseId.RESTORE_VIEW); |
46 | 50 | } |
47 | | - else if (annotation.after() == Phase.NONE && annotation.before() != Phase.NONE) { |
48 | | - deferredOperation.before(annotation.before().getPhaseId()); |
| 51 | + else if (beforePhase == null && afterPhase != null) { |
| 52 | + deferredOperation.after(afterPhase.value().getPhaseId()); |
49 | 53 | } |
50 | | - else if (annotation.after() != Phase.NONE && annotation.before() == Phase.NONE) { |
51 | | - deferredOperation.after(annotation.after().getPhaseId()); |
| 54 | + else if (beforePhase != null && afterPhase == null) { |
| 55 | + deferredOperation.before(beforePhase.value().getPhaseId()); |
52 | 56 | } |
53 | 57 | else { |
54 | 58 | throw new IllegalStateException("Error processing @" + handles().getSimpleName() + " annotation on method " |
55 | 59 | + method.getDeclaringClass().getName() + "#" + method.getName() |
56 | | - + ": You cannot use 'before' and 'after' at the same time."); |
| 60 | + + ": You cannot use @" + BeforePhase.class.getSimpleName() + " and @" |
| 61 | + + AfterPhase.class.getSimpleName() + " at the same time."); |
57 | 62 | } |
58 | 63 |
|
59 | 64 | // append this operation to the rule |
|
0 commit comments