From bd388708f400b19ebafef3ff31361d97f54ab7e7 Mon Sep 17 00:00:00 2001 From: kkolinko Date: Mon, 21 Dec 2009 20:28:45 +0000 Subject: [PATCH] Add a page that illustrates EL Composite Expressions ("${a}${b}") to the Examples web application This was designed as a reproducer for http://issues.apache.org/bugzilla/show_bug.cgi?id=47413 Currently Composite ELs are correctly evaluated to Strings, but their coercion to the resulting type is broken. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@892968 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 6 ++ .../WEB-INF/classes/examples/ValuesTag.java | 73 ++++++++++++++ .../WEB-INF/classes/jsp2/examples/ValuesBean.java | 55 +++++++++++ webapps/examples/WEB-INF/jsp/example-taglib.tld | 37 ++++++- webapps/examples/jsp/index.html | 8 ++ webapps/examples/jsp/jsp2/el/composite.html | 31 ++++++ webapps/examples/jsp/jsp2/el/composite.jsp | 110 +++++++++++++++++++++ 7 files changed, 319 insertions(+), 1 deletion(-) create mode 100644 webapps/examples/WEB-INF/classes/examples/ValuesTag.java create mode 100644 webapps/examples/WEB-INF/classes/jsp2/examples/ValuesBean.java create mode 100644 webapps/examples/jsp/jsp2/el/composite.html create mode 100644 webapps/examples/jsp/jsp2/el/composite.jsp diff --git a/build.xml b/build.xml index b8f7b9c9d..53e587cf3 100644 --- a/build.xml +++ b/build.xml @@ -657,6 +657,12 @@ + + + + + + diff --git a/webapps/examples/WEB-INF/classes/examples/ValuesTag.java b/webapps/examples/WEB-INF/classes/examples/ValuesTag.java new file mode 100644 index 000000000..5e9f70b84 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/examples/ValuesTag.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package examples; + +import javax.servlet.jsp.*; +import javax.servlet.jsp.tagext.*; + +import java.io.*; + +/** + * Accept and display a value. + */ +public class ValuesTag extends TagSupport { + // Using "-1" as the default value, + // in the assumption that it won't be used as the value. + // Cannot use null here, because null is an important case + // that should be present in the tests. + private Object objectValue = "-1"; + private String stringValue = "-1"; + private long longValue = -1; + private double doubleValue = -1; + + public void setObject(Object objectValue) { + this.objectValue = objectValue; + } + + public void setString(String stringValue) { + this.stringValue = stringValue; + } + + public void setLong(long longValue) { + this.longValue = longValue; + } + + public void setDouble(double doubleValue) { + this.doubleValue = doubleValue; + } + + public int doEndTag() throws JspException { + JspWriter out = pageContext.getOut(); + + try { + if (!"-1".equals(objectValue)) { + out.print(objectValue); + } else if (!"-1".equals(stringValue)) { + out.print(stringValue); + } else if (longValue != -1) { + out.print(longValue); + } else if (doubleValue != -1) { + out.print(doubleValue); + } else { + out.print("-1"); + } + } catch (IOException ex) { + throw new JspTagException("IOException: " + ex.toString(), ex); + } + return super.doEndTag(); + } +} diff --git a/webapps/examples/WEB-INF/classes/jsp2/examples/ValuesBean.java b/webapps/examples/WEB-INF/classes/jsp2/examples/ValuesBean.java new file mode 100644 index 000000000..718888e28 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/jsp2/examples/ValuesBean.java @@ -0,0 +1,55 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You under the Apache License, Version 2.0 +* (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +package jsp2.examples; + +/** + * Accept and display a value. + */ +public class ValuesBean { + private String string; + private double doubleValue; + private long longValue; + + public ValuesBean() { + } + + public String getString() { + return this.string; + } + + public void setString(String string) { + this.string = string; + } + + public double getDouble() { + return doubleValue; + } + + public void setDouble(double doubleValue) { + this.doubleValue = doubleValue; + } + + public long getLong() { + return longValue; + } + + public void setLong(long longValue) { + this.longValue = longValue; + } +} diff --git a/webapps/examples/WEB-INF/jsp/example-taglib.tld b/webapps/examples/WEB-INF/jsp/example-taglib.tld index d8c2659e8..e6cf82baf 100644 --- a/webapps/examples/WEB-INF/jsp/example-taglib.tld +++ b/webapps/examples/WEB-INF/jsp/example-taglib.tld @@ -79,5 +79,40 @@ false - + + + + + values + examples.ValuesTag + empty + + Accept and return values of different types. This tag is used + to illustrate type coercions. + + + object + false + true + java.lang.Object + + + string + false + true + java.lang.String + + + long + false + true + long + + + double + false + true + double + + diff --git a/webapps/examples/jsp/index.html b/webapps/examples/jsp/index.html index 3502351b4..f054cacc9 100644 --- a/webapps/examples/jsp/index.html +++ b/webapps/examples/jsp/index.html @@ -103,6 +103,14 @@ This can be done using browser options. +Composite Expressions +Execute + +Source + + + +
SimpleTag Handlers and JSP Fragments diff --git a/webapps/examples/jsp/jsp2/el/composite.html b/webapps/examples/jsp/jsp2/el/composite.html new file mode 100644 index 000000000..5900008e2 --- /dev/null +++ b/webapps/examples/jsp/jsp2/el/composite.html @@ -0,0 +1,31 @@ + + + +View Source Code + + + + +

+ +

Source Code for composite.jsp

+

Source Code for ValuesTag.java

+

Source Code for ValuesBean.java

+ + + diff --git a/webapps/examples/jsp/jsp2/el/composite.jsp b/webapps/examples/jsp/jsp2/el/composite.jsp new file mode 100644 index 000000000..fb0c6fecb --- /dev/null +++ b/webapps/examples/jsp/jsp2/el/composite.jsp @@ -0,0 +1,110 @@ + +<%@ taglib prefix="my" uri="http://tomcat.apache.org/example-taglib" %> + + + + JSP 2.0 Expression Language - Composite Expressions + + +

JSP 2.0 Expression Language - Composite Expressions

+
+ This example illustrates EL composite expressions. Composite expressions + are formed by grouping together multiple EL expressions. Each of them is + evaluated from left to right, coerced to String, all those strings are + concatenated, and the result is coerced to the expected type. + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EL ExpressionTypeResult
\${'hello'} wo\${'rld'}String${values.string}
\${'hello'} wo\${'rld'}String
\${1+2}.\${220}Double${values.double}
\${1+2}.\${220}Double
000\${1}\${7}Long${values.long}
000\${1}\${7}Long
\${undefinedFoo}hello world\${undefinedBar}String${values.string}
\${undefinedFoo}hello world\${undefinedBar}String
\${undefinedFoo}\${undefinedBar}Double${values.double}
\${undefinedFoo}\${undefinedBar}Double
\${undefinedFoo}\${undefinedBar}Long${values.long}
\${undefinedFoo}\${undefinedBar}Long
+
+
+ + + -- 2.11.0