SWF-690 - sf:clientTextValidator doesn't respect custom faces converter

This commit is contained in:
Jeremy Grelle
2008-05-23 19:10:14 +00:00
parent ebd9e5807a
commit 7ce695cd17
4 changed files with 141 additions and 10 deletions

View File

@@ -0,0 +1,85 @@
package org.springframework.faces.ui;
import java.util.Date;
import javax.faces.FacesException;
import javax.faces.component.UIInput;
import javax.faces.convert.DateTimeConverter;
import junit.framework.TestCase;
import org.springframework.faces.webflow.JSFMockHelper;
public class DojoDecorationRendererTests extends TestCase {
JSFMockHelper jsf = new JSFMockHelper();
public void setUp() throws Exception {
jsf.setUp();
}
public void tearDown() throws Exception {
jsf.tearDown();
}
public void testGetValueAsString() {
UIInput childComponent = new UIInput();
childComponent.setValue("foo");
DojoDecorationRenderer renderer = new DojoDecorationRenderer();
String convertedValue = renderer.getValueAsString(jsf.facesContext(), childComponent);
assertEquals("foo", convertedValue);
}
public void testGetValueAsString_LocalConverter() {
UIInput childComponent = new UIInput();
childComponent.setValue(new TestValue());
childComponent.setConverter(new TestConverter());
DojoDecorationRenderer renderer = new DojoDecorationRenderer();
String convertedValue = renderer.getValueAsString(jsf.facesContext(), childComponent);
assertEquals("foo", convertedValue);
}
public void testGetValueAsString_NoConverter() {
UIInput childComponent = new UIInput();
childComponent.setValue(new TestValue());
DojoDecorationRenderer renderer = new DojoDecorationRenderer();
try {
renderer.getValueAsString(jsf.facesContext(), childComponent);
fail("getValueAsString should throw exception if no converter is found");
} catch (FacesException ex) {
// expected
}
}
public void testGetValueAsString_GlobalConverter() throws Exception {
UIInput childComponent = new UIInput();
childComponent.setValue(new TestValue());
jsf.facesContext().getApplication().addConverter(TestValue.class, TestConverter.class.getName());
DojoDecorationRenderer renderer = new DojoDecorationRenderer();
String convertedValue = renderer.getValueAsString(jsf.facesContext(), childComponent);
assertEquals("foo", convertedValue);
}
public void testGetNodeAttributesAsString() {
String expectedAttributes = "name : 'foo', value : 'foo'";
UIInput childComponent = new UIInput();
childComponent.setId("foo");
childComponent.setValue("foo");
DojoDecorationRenderer renderer = new DojoDecorationRenderer();
String nodeAttributes = renderer.getNodeAttributesAsString(jsf.facesContext(), childComponent);
assertEquals(expectedAttributes, nodeAttributes);
}
public void testGetNodeAttributesAsString_DateValue() {
String expectedAttributes = "name : 'foo', value : dojo.date.locale.parse('Nov 21, 1977', "
+ "{selector : 'date', datePattern : 'yyyy-MM-dd'})";
UIInput childComponent = new UIInput();
childComponent.setConverter(new DateTimeConverter());
childComponent.setId("foo");
childComponent.setValue(new Date("11/21/1977"));
DojoDecorationRenderer renderer = new DojoDecorationRenderer();
String nodeAttributes = renderer.getNodeAttributesAsString(jsf.facesContext(), childComponent);
assertEquals(expectedAttributes, nodeAttributes);
}
}

View File

@@ -0,0 +1,20 @@
package org.springframework.faces.ui;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
public class TestConverter implements Converter {
public TestConverter() {
}
public Object getAsObject(FacesContext context, UIComponent component, String value) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Auto-generated method stub");
}
public String getAsString(FacesContext context, UIComponent component, Object value) {
return ((TestValue) value).getStringValue();
}
}

View File

@@ -0,0 +1,8 @@
package org.springframework.faces.ui;
public class TestValue {
public String getStringValue() {
return "foo";
}
}