Author: kkolinko
Date: Mon Dec 21 21:51:29 2009
New Revision: 893001
URL: http://svn.apache.org/viewvc?rev=893001&view=rev
Log:
Fix second part of Comment 8 in
https://issues.apache.org/bugzilla/show_bug.cgi?id=47413#c8
Coerce result of composite EL expression (${a}${b}) from String to the expected
type.
Modified:
tomcat/trunk/java/org/apache/jasper/compiler/Generator.java
Modified: tomcat/trunk/java/org/apache/jasper/compiler/Generator.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/Generator.java?rev=893001&r1=893000&r2=893001&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/Generator.java (original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/Generator.java Mon Dec 21
21:51:29 2009
@@ -889,6 +889,54 @@
}
output.append(quote(tx.substring(mark, i)));
}
+ if (expectedType != type && !expectedType.isAssignableFrom(type)) {
+ // Composite expression was evaluated to String
+ // We must coerce it to the expected type.
+ String className = JspUtil.getCanonicalName(expectedType);
+ String methodName = null;
+ if (expectedType.isPrimitive()) {
+ if (expectedType == Boolean.TYPE) {
+ className = "Boolean";
+ methodName = ".booleanValue()";
+ }
+ else if (expectedType == Character.TYPE) {
+ className = "Character";
+ methodName = ".charValue()";
+ }
+ else if (expectedType == Byte.TYPE) {
+ className = "Byte";
+ methodName = ".byteValue()";
+ }
+ else if (expectedType == Short.TYPE) {
+ className = "Short";
+ methodName = ".shortValue()";
+ }
+ else if (expectedType == Integer.TYPE) {
+ className = "Integer";
+ methodName = ".intValue()";
+ }
+ else if (expectedType == Long.TYPE) {
+ className = "Long";
+ methodName = ".longValue()";
+ }
+ else if (expectedType == Float.TYPE) {
+ className = "Float";
+ methodName = ".floatValue()";
+ }
+ else if (expectedType == Double.TYPE) {
+ className = "Double";
+ methodName = ".doubleValue()";
+ }
+ }
+ output.insert(0, "(("
+ + className
+ + ")org.apache.el.lang.ELSupport.coerceToType(");
+ output.append(",").append(className).append(".class))");
+ if (methodName != null) {
+ output.insert(0, '(');
+ output.append(methodName).append(')');
+ }
+ }
return output.toString();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]