Bug 45040 - null string from web is converted to 0 in JSF
null string from web is converted to 0 in JSF
Status: RESOLVED DUPLICATE of bug 43285
Product: Tomcat 6
Classification: Unclassified
Component: Jasper
6.0.16
All All
: P2 critical (vote)
: default
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2008-05-19 11:03 UTC by jason zhang
Modified: 2008-05-19 11:55 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jason zhang 2008-05-19 11:03:49 UTC
My Environment is JSF 1.2(sun RI)+facelet+tomcat 6.0.16. There is an integer field in my web form. I monitored the submitted form using the tcpmon. The value is indeed empty.  Debugging confirmed that the submitted value is empty. However, when it is "update model" in JSF, the value becomes Integer(0) while I expect a null object. I traced the code down to AstValue.setValue() 
 
line 1132:        resolver.setValue(ctx, t.base, t.property,
                        // coerce to the expected type                                                                                                       
                        ELSupport.coerceToType(value,
                                         resolver.getType(ctx, t.base, t.property)));

which calls 

java/org/apache/el/lang/ELSupport.java
line 198:  public final static Number coerceToNumber(final Object obj) {
line 199:        if (obj == null) {
line 200:           return ZERO;

The ELSupport here converts a null object to zero object. This makes it impossible to differentiate "an empty field" from "a field with 0" from web in JSF model object.


Maybe the setValue in AstValue should be changed to
 resolver.setValue(ctx, t.base, t.property, value==null?null:                                                                    ELSupport.coerceToType(value, resolver.getType(ctx, t.base, t.property)));

thanks

-jason
Comment 1 Mark Thomas 2008-05-19 11:49:04 UTC
This behaviour us as oer the soec

*** This bug has been marked as a duplicate of bug 43285 ***
Comment 2 Mark Thomas 2008-05-19 11:55:39 UTC
Sorry about the typing. It should have said "as per the spec"