1515 */
1616package org .ocpsoft .rewrite .faces .config ;
1717
18- import java .util .ArrayList ;
1918import java .util .Arrays ;
2019import java .util .HashSet ;
21- import java .util .List ;
2220import java .util .Set ;
2321
2422import javax .faces .event .PhaseId ;
2523
2624import org .ocpsoft .rewrite .bind .Binding ;
2725import org .ocpsoft .rewrite .bind .Submission ;
28- import org .ocpsoft .rewrite .config .CompositeOperation ;
2926import org .ocpsoft .rewrite .config .Operation ;
3027import org .ocpsoft .rewrite .context .EvaluationContext ;
3128import org .ocpsoft .rewrite .event .Rewrite ;
4441 * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
4542 * @author <a href="mailto:fabmars@gmail.com">Fabien Marsaud</a>
4643 */
47- public class PhaseBinding extends HttpOperation implements Binding , CompositeOperation
44+ public class PhaseBinding implements Binding
4845{
4946 private final Set <PhaseId > beforePhases = new HashSet <PhaseId >();
5047 private final Set <PhaseId > afterPhases = new HashSet <PhaseId >();
5148
5249 private final Submission deferred ;
53- private Object deferredValue ;
5450
5551 private Validator <?> validator ;
5652 private Converter <?> converter ;
@@ -119,24 +115,6 @@ public PhaseBinding onValidationFailure(Operation operation)
119115 return this ;
120116 }
121117
122- @ Override
123- public void performHttp (HttpServletRewrite event , EvaluationContext context )
124- {
125- Object value = deferredValue ;
126- if (converter != null )
127- value = ValueHolderUtil .convert (event , context , converter , value );
128-
129- if (validator != null && !ValueHolderUtil .validates (event , context , validator , value ))
130- {
131- if (operation != null )
132- operation .perform (event , context );
133- }
134- else
135- {
136- deferred .submit (event , context , value );
137- }
138- }
139-
140118 @ Override
141119 public Object retrieve (Rewrite event , EvaluationContext context )
142120 {
@@ -146,12 +124,11 @@ public Object retrieve(Rewrite event, EvaluationContext context)
146124 @ Override
147125 public Object submit (Rewrite event , EvaluationContext context , Object value )
148126 {
149- deferredValue = value ;
150127
151128 /**
152129 * Must occur before queued {@link PhaseAction} instances during the same phase.
153130 */
154- PhaseOperation .enqueue (this , -5 )
131+ PhaseOperation .enqueue (new PhaseBindingOperation ( value ) , -5 )
155132 .before (beforePhases .toArray (new PhaseId [] {}))
156133 .after (afterPhases .toArray (new PhaseId [] {}))
157134 .perform (event , context );
@@ -171,12 +148,36 @@ public boolean supportsSubmission()
171148 return true ;
172149 }
173150
174- @ Override
175- public List <Operation > getOperations ()
151+ private class PhaseBindingOperation extends HttpOperation
176152 {
177- ArrayList <Operation > operations = new ArrayList <Operation >();
178- if (operation != null )
179- operations .add (operation );
180- return operations ;
153+
154+ private Object value ;
155+
156+ public PhaseBindingOperation (Object value )
157+ {
158+ this .value = value ;
159+ }
160+
161+ @ Override
162+ public void performHttp (HttpServletRewrite event , EvaluationContext context )
163+ {
164+
165+ Object converted = value ;
166+
167+ if (converter != null )
168+ converted = ValueHolderUtil .convert (event , context , converter , value );
169+
170+ if (validator != null && !ValueHolderUtil .validates (event , context , validator , converted ))
171+ {
172+ if (operation != null )
173+ operation .perform (event , context );
174+ }
175+ else
176+ {
177+ deferred .submit (event , context , converted );
178+ }
179+ }
180+
181181 }
182+
182183}
0 commit comments