You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ca...@apache.org on 2007/03/15 10:58:24 UTC
svn commit: r518553 - in /myfaces/core/branches/jsf12/api/src:
main/java-templates/javax/faces/component/UIInputTemplate.java
test/java/javax/faces/component/UIInputTest.java
Author: cagatay
Date: Thu Mar 15 02:58:24 2007
New Revision: 518553
URL: http://svn.apache.org/viewvc?view=rev&rev=518553
Log:
Applied 1.2 changes on updatemodel(), replaced valuebinding with valueexpression, elexception with
evaluationexception, mark component as invalid in case exception occurs, use new UPDATE_MODEL error message.
Also added tests.
Modified:
myfaces/core/branches/jsf12/api/src/main/java-templates/javax/faces/component/UIInputTemplate.java
myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIInputTest.java
Modified: myfaces/core/branches/jsf12/api/src/main/java-templates/javax/faces/component/UIInputTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java-templates/javax/faces/component/UIInputTemplate.java?view=diff&rev=518553&r1=518552&r2=518553
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java-templates/javax/faces/component/UIInputTemplate.java (original)
+++ myfaces/core/branches/jsf12/api/src/main/java-templates/javax/faces/component/UIInputTemplate.java Thu Mar 15 02:58:24 2007
@@ -15,6 +15,8 @@
*/
package javax.faces.component;
+import javax.el.ELException;
+import javax.el.ValueExpression;
import javax.faces.validator.Validator;
import javax.faces.el.MethodBinding;
import javax.faces.el.EvaluationException;
@@ -188,32 +190,31 @@
{
if (!isValid()) return;
if (!isLocalValueSet()) return;
- ValueBinding vb = getValueBinding("value");
- if (vb == null) return;
+ ValueExpression expression = getValueExpression("value");
+ if (expression == null) return;
try
{
- vb.setValue(context, getLocalValue());
+ expression.setValue(context.getELContext(), getLocalValue());
setValue(null);
setLocalValueSet(false);
}
- catch (EvaluationException ee)
+ catch (ELException elException)
{
- String exceptionMessage = ee.getMessage();
+ String exceptionMessage = elException.getMessage();
if (exceptionMessage == null)
{
- _MessageUtils.addErrorMessage(context, this,
- CONVERSION_MESSAGE_ID, new Object[] { getId() });
+ _MessageUtils.addErrorMessage(context, this, UPDATE_MESSAGE_ID, new Object[]{_MessageUtils.getLabel(context,this)});
}
else
{
- _MessageUtils.addErrorMessage(context, this, ee);
+ _MessageUtils.addErrorMessage(context, this, elException);
}
+ setValid(false);
}
- catch (RuntimeException e)
+ catch (Exception e)
{
- //Object[] args = {getId()};
context.getExternalContext().log(e.getMessage(), e);
- _MessageUtils.addErrorMessage(context, this,CONVERSION_MESSAGE_ID,new Object[]{getId()});
+ _MessageUtils.addErrorMessage(context, this, UPDATE_MESSAGE_ID, new Object[]{_MessageUtils.getLabel(context,this)});
setValid(false);
}
}
Modified: myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIInputTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIInputTest.java?view=diff&rev=518553&r1=518552&r2=518553
==============================================================================
--- myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIInputTest.java (original)
+++ myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIInputTest.java Thu Mar 15 02:58:24 2007
@@ -20,6 +20,7 @@
import static org.easymock.EasyMock.*;
+import javax.el.ValueExpression;
import javax.faces.application.FacesMessage;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
@@ -29,11 +30,13 @@
import junit.framework.Test;
import org.apache.shale.test.base.AbstractJsfTestCase;
+import org.apache.shale.test.el.MockValueExpression;
public class UIInputTest extends AbstractJsfTestCase{
private Converter mockConverter;
private Validator mockValidator;
+ private UIInput input;
public UIInputTest(String name) {
super(name);
@@ -41,12 +44,15 @@
protected void setUp() throws Exception {
super.setUp();
+ input = new UIInput();
+ input.setId("testId");
mockConverter = createMock(Converter.class);
mockValidator = createMock(Validator.class);
}
protected void tearDown() throws Exception {
super.tearDown();
+ input = null;
mockConverter = null;
mockValidator = null;
}
@@ -56,8 +62,6 @@
}
public void testWhenSpecifiedConverterMessageIsUsedInCaseConverterExceptionOccurs() {
- UIInput input = new UIInput();
- input.setId("testId");
input.setConverterMessage("Cannot convert");
input.setConverter(mockConverter);
@@ -76,8 +80,6 @@
}
public void testWhenSpecifiedValidatorMessageIsUsedInCaseValidatorExceptionOccurs() {
- UIInput input = new UIInput();
- input.setId("testId");
input.setValidatorMessage("Cannot validate");
input.addValidator(mockValidator);
@@ -94,5 +96,17 @@
FacesMessage message = (FacesMessage) facesContext.getMessages("testId").next();
assertEquals(message.getDetail(), "Cannot validate");
assertEquals(message.getSummary(), "Cannot validate");
+ }
+
+ public void testUpdateModelSetsTheLocalValueToModelValue() {
+ input.setValue("testValue");
+
+ ValueExpression expression = new MockValueExpression("#{requestScope.id}",String.class);
+ input.setValueExpression("value", expression);
+
+ input.updateModel(facesContext);
+
+ String updatedValue = expression.getValue(facesContext.getELContext()).toString();
+ assertEquals("testValue", updatedValue);
}
}