Hi, Thanks for point this out. So, maybe my next question is more of a JSF question, but I'll give a shot. Why does the javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL even exist then? It will always be overruled by the EL parser when actually setting the value, at least as of EL3 In other words is there any way to revert to the old behavior using tomcat8 icw JSF?
-----Original Message----- From: Violeta Georgieva [mailto:miles...@gmail.com] Sent: woensdag 15 oktober 2014 10:57 To: Tomcat Developers List Subject: Re: Tomcat8 coercing behavior Hi, 2014-10-15 11:38 GMT+03:00 Koen Serneels <k...@error.be>: > > Hi, > > > > When binding a JSF input text to a String property of a JSF > ManagedBean, I want that an empty value is mapped to null and not "" (empty > string). > > So, on tomcat7 (7.0.56) with JSF(2.2) I can get this to work nicely by > controlling the coercing behavior with the JVM property > org.apache.el.parser.COERCE_TO_ZERO icw JSF > javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL as context > param. > > > > When javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL is > set to true, JSF will set the local component value for the input > component as null > when the input if left empty. > > Next, when the value is actually set by tomcat's EL parser, it will > NOT try > to coerce the value when org.apache.el.parser.COERCE_TO_ZERO is set to > false. > > This can be seen in org.apache.el.parser.AstValue#216: > > > > if (COERCE_TO_ZERO == true > > || !isAssignable(value, targetClass)) { > > resolver.setValue(ctx, t.base, t.property, > > ELSupport.coerceToType(value, targetClass)); > > } else { > > resolver.setValue(ctx, t.base, t.property, value); > > } > > > > So, in this case I get 'null' instead of "" => OK > > > > However, if I now try this on tomcat8 (8.0.14), this no longer works. > org.apache.el.parser.AstValue#200 now does this: > > > > resolver.setValue(ctx, t.base, t.property, > > ELSupport.coerceToType(value, targetClass)); > > > > So ELSupport is ALWAYS executed, it will ignore the first 2 IF > statements (as my target type is String): > > > > public static final Object coerceToType(final Object obj, > > final Class<?> type) throws ELException { > > > > if (type == null || Object.class.equals(type) || > > (obj != null && > type.isAssignableFrom(obj.getClass()))) { > > return obj; > > } > > > > if (!COERCE_TO_ZERO) { > > if (obj == null && !type.isPrimitive() && > > !String.class.isAssignableFrom(type)) { > > return null; > > } > > } > > > > if (String.class.equals(type)) { > > return coerceToString(obj); > > } > > > > And this will eventually call "coerceToString", which will always > return "" > if the value was null : > > > > public static final String coerceToString(final Object obj) { > > if (obj == null) { > > return ""; > > > > So, from tomcat8 I always get "" instead of the desired null. This is incompatible change in EL 3.0. Check EL 3.0 Spec 1.23.1 and 1.23.2 the Rule for null String is to coerce to "". and A.4 Incompatibilities between EL 3.0 and EL 2.2 Regards Violeta > > I know this is related to the specification (this goes as far back as > tomcat6) but now I'm getting really confused here as this worked on 6 > and 7 > but no longer on 8 > > Is this a bug or am I missing something here? > > > > Thanks, > > > > Koen. > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org