I have a domain object called Total that contains property named amount.
package domain;
public class Total {
private float amount;
public float getAmount() {
return amount;
}
public void setAmount( float amount) {
this.amount = amount;
}
}
The amount proerty is binded to the inputText on the page. When the user enters value greater then 2^14(16777216) the updated model value becomes inconsistent. For example the value: 16777217 is converted and updated to the model as 16777216. Here is the shale test case i wrote to test the situation. There is an assertNotSame() method at the end of the testCase which should be an assertSame().
package domain;
public class Total {
private float amount;
public float getAmount() {
return amount;
}
public void setAmount( float amount) {
this.amount = amount;
}
}
The amount proerty is binded to the inputText on the page. When the user enters value greater then 2^14(16777216) the updated model value becomes inconsistent. For example the value: 16777217 is converted and updated to the model as 16777216. Here is the shale test case i wrote to test the situation. There is an assertNotSame() method at the end of the testCase which should be an assertSame().
package dev; import javax.faces.component.UIForm; import javax.faces.component.UIInput; import javax.faces.component.html.HtmlForm; import javax.faces.component.html.HtmlInputText; import javax.faces.convert.NumberConverter; import javax.faces.el.ValueBinding; import junit.framework.Test; import junit.framework.TestSuite; import org.apache.shale.test.base.AbstractJsfTestCase; import com.sun.faces.renderkit.html_basic.TextRenderer; import domain.Total; public class NumberConverterTester extends AbstractJsfTestCase { private UIInput inputText; NumberConverter converter; private TextRenderer inputTextRenderer; public NumberConverterTester(String testName) { super(testName); } public static Test suite() { return new TestSuite(NumberConverterTester.class); } public void setUp() { super.setUp(); // view UIForm form = new HtmlForm(); form.setId("form1"); form.setParent(facesContext.getViewRoot()); // the component inputText = new HtmlInputText(); inputText.setId("text1"); inputText.setParent(form); // the converter converter = new NumberConverter(); converter.setType("number"); inputText.setConverter(converter); Total myTotal = new Total(); ValueBinding valueBinding = facesContext.getApplication().createValueBinding("#{myTotal.amount}"); inputText.setValueBinding("value", valueBinding); facesContext.getExternalContext().getRequestMap().put("myTotal", myTotal); } public void tearDown() { super.tearDown(); } public void testConvertWorksFineWithPrimitiveFloatValueEquals2over24() { facesContext.getExternalContext().getRequestParameterMap().put("form1:text1", "16777216"); inputTextRenderer = new TextRenderer(); inputTextRenderer.decode(facesContext, inputText); inputText.processValidators(facesContext); inputText.processUpdates(facesContext); Total amountFromModel = (Total) facesContext.getApplication().getVariableResolver().resolveVariable(facesContext, "myTotal"); String amount = inputText.getConverter().getAsString(facesContext,inputText, new Float(amountFromModel.getAmount())); assertEquals(amount, "16.777.216"); } public void testConvertDoesntWorkRightWithPrimitiveFloatValueAbove2over24() { facesContext.getExternalContext().getRequestParameterMap().put("form1:text1", "16777217"); inputTextRenderer = new TextRenderer(); inputTextRenderer.decode(facesContext, inputText); inputText.processValidators(facesContext); inputText.processUpdates(facesContext); Total amountFromModel = (Total) facesContext.getApplication().getVariableResolver().resolveVariable(facesContext, "myTotal"); String amount = inputText.getConverter().getAsString(facesContext,inputText, new Float(amountFromModel.getAmount())); assertNotSame(amount, "16.777.217"); } }
I tested this with jsf 1.1_02. Any ideas? Is there a problem with the spec. or something else?
Regards,
Mert..