You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2009/11/21 01:59:14 UTC
svn commit: r882809 - in /myfaces/core/trunk/api/src:
main/java/javax/faces/component/UIViewRoot.java
test/java/javax/faces/component/UIInputTest.java
Author: lu4242
Date: Sat Nov 21 00:59:13 2009
New Revision: 882809
URL: http://svn.apache.org/viewvc?rev=882809&view=rev
Log:
the call of context.renderResponse or context.responseComplete does not stop phase execution (and add some additional tests for UIInput.validate() method)
Modified:
myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewRoot.java
myfaces/core/trunk/api/src/test/java/javax/faces/component/UIInputTest.java
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewRoot.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewRoot.java?rev=882809&r1=882808&r2=882809&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewRoot.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewRoot.java Sat Nov 21 00:59:13 2009
@@ -1210,7 +1210,12 @@
*/
private boolean _process(FacesContext context, PhaseId phaseId, PhaseProcessor processor)
{
- if (!notifyListeners(context, phaseId, getBeforePhaseListener(), true))
+ // If context.renderResponse() or context.responseComplete has been called on any listener before phase,
+ // the phase should continue. Note that after the phase has ended this conditions are checked by
+ // the lifecycle, and you can always put that kind of code on after phase listener instead.
+ notifyListeners(context, phaseId, getBeforePhaseListener(), true);
+
+ try
{
if (processor != null)
{
@@ -1219,10 +1224,12 @@
broadcastEvents(context, phaseId);
}
-
- if (context.getRenderResponse() || context.getResponseComplete())
+ finally
{
- clearEvents();
+ if (context.getRenderResponse() || context.getResponseComplete())
+ {
+ clearEvents();
+ }
}
return notifyListeners(context, phaseId, getAfterPhaseListener(), false);
Modified: myfaces/core/trunk/api/src/test/java/javax/faces/component/UIInputTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/test/java/javax/faces/component/UIInputTest.java?rev=882809&r1=882808&r2=882809&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/test/java/javax/faces/component/UIInputTest.java (original)
+++ myfaces/core/trunk/api/src/test/java/javax/faces/component/UIInputTest.java Sat Nov 21 00:59:13 2009
@@ -24,23 +24,27 @@
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
+import javax.faces.el.MethodBinding;
+import javax.faces.event.PhaseId;
+import javax.faces.event.ValueChangeEvent;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
-import javax.faces.context.ExternalContext;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shale.test.base.AbstractJsfTestCase;
+import org.apache.shale.test.el.MockMethodExpression;
import org.apache.shale.test.el.MockValueExpression;
-import org.apache.shale.test.mock.MockExternalContext12;
-
-import java.util.Map;
-import java.util.HashMap;
public class UIInputTest extends AbstractJsfTestCase
{
@@ -72,6 +76,74 @@
mockConverter = null;
mockValidator = null;
}
+
+ public static class MyMockValueChangeBean
+ {
+ public void changeValue(ValueChangeEvent evt)
+ {
+ throw new IllegalStateException("method should not be called");
+ }
+ }
+
+ public static class MyMockValidatorBean implements Validator
+ {
+ public void validate(FacesContext context, UIComponent component,
+ Object value) throws ValidatorException
+ {
+ ((UIInput)component).setValid(false);
+ }
+ }
+
+ public void testValidateNotCallValueChangeListenerWhenCallValidateWithBinding()
+ {
+ MethodExpression itemValue = new MockMethodExpression("#{valueChangeBean.changeValue}",
+ new Class[]{ValueChangeEvent.class} , MyMockValueChangeBean.class);
+ externalContext.getRequestMap().put("valueChangeBean", new MyMockValueChangeBean());
+ input.setValueChangeListener(new _MethodExpressionToMethodBinding(itemValue));
+
+ request.setAttribute("mockValidator",new MyMockValidatorBean());
+
+ MethodBinding binding = application.createMethodBinding(
+ "#{requestScope.mockValidator.validate}",
+ new Class[] { FacesContext.class, UIComponent.class, Object.class }
+ );
+ input.setValidator(binding);
+
+ UIViewRoot root = new UIViewRoot();
+
+ root.getChildren().add(input);
+ input.setSubmittedValue("xxx");
+ input.processValidators(facesContext);
+ input.setValid(true);
+ input.processValidators(facesContext);
+ root.broadcastEvents(facesContext, PhaseId.PROCESS_VALIDATIONS);
+ assertNotNull(input.getSubmittedValue());
+ }
+
+ public void testValidateNotCallValueChangeListenerWhenCallValidateWithValidator()
+ {
+ MethodExpression itemValue = new MockMethodExpression("#{valueChangeBean.changeValue}",
+ new Class[]{ValueChangeEvent.class} , MyMockValueChangeBean.class);
+ externalContext.getRequestMap().put("valueChangeBean", new MyMockValueChangeBean());
+ input.setValueChangeListener(new _MethodExpressionToMethodBinding(itemValue));
+
+ input.addValidator(new Validator(){
+
+ public void validate(FacesContext context, UIComponent component,
+ Object value) throws ValidatorException
+ {
+ ((UIInput)component).setValid(false);
+ }
+ });
+
+ UIViewRoot root = new UIViewRoot();
+
+ root.getChildren().add(input);
+ input.setSubmittedValue("xxx");
+ input.processValidators(facesContext);
+ root.broadcastEvents(facesContext, PhaseId.PROCESS_VALIDATIONS);
+ assertNotNull(input.getSubmittedValue());
+ }
public void testWhenSpecifiedConverterMessageIsUsedInCaseConverterExceptionOccurs()
{