2121 */
2222package com .ocpsoft .rewrite .faces ;
2323
24- import java .util .List ;
24+ import java .util .ArrayList ;
2525
2626import javax .faces .application .NavigationHandler ;
2727import javax .faces .context .FacesContext ;
3131import javax .servlet .http .HttpServletRequest ;
3232
3333import com .ocpsoft .logging .Logger ;
34- import com .ocpsoft .rewrite .faces .config .PhaseOperation ;
3534import com .ocpsoft .rewrite .faces .config .PhaseAction ;
36- import com .ocpsoft .rewrite .faces .config .PhaseBinding ;
37- import com .ocpsoft .rewrite .faces .config .QueuedPhaseAction ;
35+ import com .ocpsoft .rewrite .faces .config .PhaseOperation ;
3836
3937/**
4038 * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
@@ -55,95 +53,57 @@ public void afterPhase(final PhaseEvent event)
5553 {
5654 if (!PhaseId .RENDER_RESPONSE .equals (event .getPhaseId ()))
5755 {
58- handleAfterPhaseInjections (event );
59- handleAfterPhaseActions (event );
56+ handleAfterPhaseOperations (event );
6057 handleNavigation (event );
6158 }
62- else
63- {
64- FacesContext facesContext = event .getFacesContext ();
65- HttpServletRequest request = ((HttpServletRequest ) facesContext .getExternalContext ().getRequest ());
66- PhaseBinding .removeDefferredOperations (request );
67- }
6859 }
6960
7061 @ Override
7162 public void beforePhase (final PhaseEvent event )
7263 {
7364 if (!PhaseId .RESTORE_VIEW .equals (event .getPhaseId ()))
7465 {
75- handleBeforePhaseInjections (event );
76- handleBeforePhaseActions (event );
66+ handleBeforePhaseOperations (event );
7767 }
7868
7969 if (PhaseId .RENDER_RESPONSE .equals (event .getPhaseId ()))
8070 handleNavigation (event );
8171 }
8272
83- private void handleBeforePhaseActions (final PhaseEvent event )
84- {
85- FacesContext facesContext = event .getFacesContext ();
86- HttpServletRequest request = ((HttpServletRequest ) facesContext .getExternalContext ().getRequest ());
87-
88- List <QueuedPhaseAction > actions = PhaseAction .getQueuedPhaseActions (request );
89- if (actions != null )
90- for (QueuedPhaseAction action : actions ) {
91- if (action .getBeforePhases ().contains (event .getPhaseId ())
92- || action .getBeforePhases ().contains (PhaseId .ANY_PHASE ))
93- {
94- action .perform ();
95- }
96- }
97- }
98-
99- private void handleAfterPhaseActions (final PhaseEvent event )
73+ private void handleBeforePhaseOperations (final PhaseEvent event )
10074 {
10175 FacesContext facesContext = event .getFacesContext ();
10276 HttpServletRequest request = ((HttpServletRequest ) facesContext .getExternalContext ().getRequest ());
10377
104- List <QueuedPhaseAction > actions = PhaseAction .getQueuedPhaseActions (request );
105- if (actions != null )
106- for (QueuedPhaseAction action : actions ) {
107- if (action .getAfterPhases ().contains (event .getPhaseId ())
108- || action .getAfterPhases ().contains (PhaseId .ANY_PHASE ))
109- {
110- action .perform ();
111- }
112- }
113- }
114-
115- private void handleBeforePhaseInjections (final PhaseEvent event )
116- {
117- FacesContext facesContext = event .getFacesContext ();
118- HttpServletRequest request = ((HttpServletRequest ) facesContext .getExternalContext ().getRequest ());
119-
120- List <PhaseOperation > operations = PhaseBinding .getDeferredOperations (request );
78+ ArrayList <PhaseOperation <?>> operations = PhaseOperation .getSortedPhaseOperations (request );
12179 if (operations != null )
122- for ( PhaseOperation operation : operations ) {
123- if (! operation . isConsumed ()
124- && ( event . getPhaseId ().equals ( operation . getBeforePhase ())
125- || PhaseId . ANY_PHASE . equals ( operation .getBeforePhase ()) ))
80+ {
81+ for ( PhaseOperation <?> operation : operations ) {
82+ if ( operation . getBeforePhases ().contains ( event . getPhaseId ())
83+ || operation .getBeforePhases (). contains ( PhaseId . ANY_PHASE ))
12684 {
127- operation .performDeferredOperation ( );
85+ operation .performOperation ( operation . getEvent (), operation . getContext () );
12886 }
12987 }
88+ }
13089 }
13190
132- private void handleAfterPhaseInjections (final PhaseEvent event )
91+ private void handleAfterPhaseOperations (final PhaseEvent event )
13392 {
13493 FacesContext facesContext = event .getFacesContext ();
13594 HttpServletRequest request = ((HttpServletRequest ) facesContext .getExternalContext ().getRequest ());
13695
137- List <PhaseOperation > operations = PhaseBinding . getDeferredOperations (request );
96+ ArrayList <PhaseOperation <?>> operations = PhaseOperation . getSortedPhaseOperations (request );
13897 if (operations != null )
139- for ( PhaseOperation operation : operations ) {
140- if (! operation . isConsumed ()
141- && ( event . getPhaseId ().equals ( operation . getAfterPhase ())
142- || PhaseId . ANY_PHASE . equals ( operation .getAfterPhase ()) ))
98+ {
99+ for ( PhaseOperation <?> operation : operations ) {
100+ if ( operation . getAfterPhases ().contains ( event . getPhaseId ())
101+ || operation .getAfterPhases (). contains ( PhaseId . ANY_PHASE ))
143102 {
144- operation .performDeferredOperation ( );
103+ operation .performOperation ( operation . getEvent (), operation . getContext () );
145104 }
146105 }
106+ }
147107 }
148108
149109 public void handleNavigation (final PhaseEvent event )
0 commit comments