Author: kkolinko
Date: Mon Dec 21 20:28:45 2009
New Revision: 892968

URL: http://svn.apache.org/viewvc?rev=892968&view=rev
Log:
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.

Added:
    tomcat/trunk/webapps/examples/WEB-INF/classes/examples/ValuesTag.java   
(with props)
    tomcat/trunk/webapps/examples/WEB-INF/classes/jsp2/examples/ValuesBean.java 
  (with props)
    tomcat/trunk/webapps/examples/jsp/jsp2/el/composite.html   (with props)
    tomcat/trunk/webapps/examples/jsp/jsp2/el/composite.jsp   (with props)
Modified:
    tomcat/trunk/build.xml
    tomcat/trunk/webapps/examples/WEB-INF/jsp/example-taglib.tld
    tomcat/trunk/webapps/examples/jsp/index.html

Modified: tomcat/trunk/build.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/build.xml?rev=892968&r1=892967&r2=892968&view=diff
==============================================================================
--- tomcat/trunk/build.xml (original)
+++ tomcat/trunk/build.xml Mon Dec 21 20:28:45 2009
@@ -657,6 +657,12 @@
     </txt2html>
 
     <txt2html todir="${tomcat.build}/webapps/examples/jsp/jsp2/el">
+      <fileset dir="webapps/examples/WEB-INF/classes/examples">
+        <include name="ValuesTag.java"/>
+      </fileset>
+      <fileset dir="webapps/examples/WEB-INF/classes/jsp2/examples">
+        <include name="ValuesBean.java"/>
+      </fileset>
       <fileset dir="webapps/examples/WEB-INF/classes/jsp2/examples/el">
         <include name="Functions.java"/>
       </fileset>

Added: tomcat/trunk/webapps/examples/WEB-INF/classes/examples/ValuesTag.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/examples/ValuesTag.java?rev=892968&view=auto
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/examples/ValuesTag.java 
(added)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/examples/ValuesTag.java Mon 
Dec 21 20:28:45 2009
@@ -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();
+    }
+}

Propchange: 
tomcat/trunk/webapps/examples/WEB-INF/classes/examples/ValuesTag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
tomcat/trunk/webapps/examples/WEB-INF/classes/jsp2/examples/ValuesBean.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/jsp2/examples/ValuesBean.java?rev=892968&view=auto
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/jsp2/examples/ValuesBean.java 
(added)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/jsp2/examples/ValuesBean.java 
Mon Dec 21 20:28:45 2009
@@ -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;
+    }
+}

Propchange: 
tomcat/trunk/webapps/examples/WEB-INF/classes/jsp2/examples/ValuesBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/webapps/examples/WEB-INF/jsp/example-taglib.tld
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/jsp/example-taglib.tld?rev=892968&r1=892967&r2=892968&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/jsp/example-taglib.tld (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/jsp/example-taglib.tld Mon Dec 21 
20:28:45 2009
@@ -79,5 +79,40 @@
        <required>false</required>
     </attribute>
   </tag>
-  
+
+  <!-- Another simple Tag -->
+  <!-- values tag -->
+  <tag>
+    <name>values</name>
+    <tag-class>examples.ValuesTag</tag-class>
+    <body-content>empty</body-content>
+    <description>
+        Accept and return values of different types. This tag is used
+        to illustrate type coercions.
+    </description>
+    <attribute>
+      <name>object</name>
+      <required>false</required>
+      <rtexprvalue>true</rtexprvalue>
+      <type>java.lang.Object</type>
+    </attribute>
+    <attribute>
+      <name>string</name>
+      <required>false</required>
+      <rtexprvalue>true</rtexprvalue>
+      <type>java.lang.String</type>
+    </attribute>
+    <attribute>
+      <name>long</name>
+      <required>false</required>
+      <rtexprvalue>true</rtexprvalue>
+      <type>long</type>
+    </attribute>
+    <attribute>
+      <name>double</name>
+      <required>false</required>
+      <rtexprvalue>true</rtexprvalue>
+      <type>double</type>
+    </attribute>
+  </tag>
 </taglib>

Modified: tomcat/trunk/webapps/examples/jsp/index.html
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/jsp/index.html?rev=892968&r1=892967&r2=892968&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/jsp/index.html (original)
+++ tomcat/trunk/webapps/examples/jsp/index.html Mon Dec 21 20:28:45 2009
@@ -103,6 +103,14 @@
 </tr>
 
 <tr valign=TOP>
+<td>Composite Expressions</td>
+<td valign=TOP width="30%"><a href="jsp2/el/composite.jsp"><img 
src="images/execute.gif" hspace=4 border=0  align=top></a><a 
href="jsp2/el/composite.jsp">Execute</a></td>
+
+<td width="30%"><a href="jsp2/el/composite.html"><img SRC="images/code.gif" 
HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a 
href="jsp2/el/composite.html">Source</a></td>
+</tr>
+
+
+<tr valign=TOP>
 <td><br><b>SimpleTag Handlers and JSP Fragments</b></td>
 </tr>
 

Added: tomcat/trunk/webapps/examples/jsp/jsp2/el/composite.html
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/jsp/jsp2/el/composite.html?rev=892968&view=auto
==============================================================================
--- tomcat/trunk/webapps/examples/jsp/jsp2/el/composite.html (added)
+++ tomcat/trunk/webapps/examples/jsp/jsp2/el/composite.html Mon Dec 21 
20:28:45 2009
@@ -0,0 +1,31 @@
+<html>
+<!--
+ 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.
+-->
+<head>
+<title>View Source Code</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+
+<body bgcolor="#FFFFFF">
+<p><font color="#0000FF"><a href="composite.jsp"><img 
src="../../images/execute.gif" align="right" border="0"></a><a 
href="../../index.html"><img src="../../images/return.gif" width="24" 
height="24" align="right" border="0"></a></font></p>
+
+<h3><a href="composite.jsp.html">Source Code for composite.jsp</a></h3>
+<h3><a href="ValuesTag.java.html">Source Code for ValuesTag.java</a></h3>
+<h3><a href="ValuesBean.java.html">Source Code for ValuesBean.java</a></h3>
+
+</body>
+</html>

Propchange: tomcat/trunk/webapps/examples/jsp/jsp2/el/composite.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tomcat/trunk/webapps/examples/jsp/jsp2/el/composite.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: tomcat/trunk/webapps/examples/jsp/jsp2/el/composite.jsp
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/jsp/jsp2/el/composite.jsp?rev=892968&view=auto
==============================================================================
--- tomcat/trunk/webapps/examples/jsp/jsp2/el/composite.jsp (added)
+++ tomcat/trunk/webapps/examples/jsp/jsp2/el/composite.jsp Mon Dec 21 20:28:45 
2009
@@ -0,0 +1,110 @@
+<!--
+ 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.
+-->
+<%@ taglib prefix="my" uri="http://tomcat.apache.org/example-taglib"; %>
+
+<html>
+  <head>
+    <title>JSP 2.0 Expression Language - Composite Expressions</title>
+  </head>
+  <body>
+    <h1>JSP 2.0 Expression Language - Composite Expressions</h1>
+    <hr>
+    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.
+
+    <jsp:useBean id="values" class="jsp2.examples.ValuesBean" />
+
+    <blockquote>
+      <code>
+        <table border="1">
+          <thead>
+        <td><b>EL Expression</b></td>
+        <td><b>Type</b></td>
+        <td><b>Result</b></td>
+      </thead>
+      <tr>
+        <td>\${'hello'} wo\${'rld'}</td>
+        <td>String</td>
+        <td><jsp:setProperty name="values" property="string" value="${'hello'} 
wo${'rld'}"/>${values.string}</td>
+      </tr>
+      <tr>
+        <td>\${'hello'} wo\${'rld'}</td>
+        <td>String</td>
+        <td><my:values string="${'hello'} wo${'rld'}"/></td>
+      </tr>
+      <tr>
+        <td>\${1+2}.\${220}</td>
+        <td>Double</td>
+        <td><jsp:setProperty name="values" property="double" 
value="${1+2}.${220}"/>${values.double}</td>
+      </tr>
+      <tr>
+        <td>\${1+2}.\${220}</td>
+        <td>Double</td>
+        <td><my:values double="${1+2}.${220}"/></td>
+      </tr>
+      <tr>
+        <td>000\${1}\${7}</td>
+        <td>Long</td>
+        <td><jsp:setProperty name="values" property="long" 
value="000${1}${7}"/>${values.long}</td>
+      </tr>
+      <tr>
+        <td>000\${1}\${7}</td>
+        <td>Long</td>
+        <td><my:values long="000${1}${7}"/></td>
+      </tr>
+      <!--
+         Undefined values are to be coerced to String, to be "",
+         https://issues.apache.org/bugzilla/show_bug.cgi?id=47413 
+       -->
+      <tr>
+        <td>\${undefinedFoo}hello world\${undefinedBar}</td>
+        <td>String</td>
+        <td><jsp:setProperty name="values" property="string" 
value="${undefinedFoo}hello world${undefinedBar}"/>${values.string}</td>
+      </tr>
+      <tr>
+        <td>\${undefinedFoo}hello world\${undefinedBar}</td>
+        <td>String</td>
+        <td><my:values string="${undefinedFoo}hello 
world${undefinedBar}"/></td>
+      </tr>
+      <tr>
+        <td>\${undefinedFoo}\${undefinedBar}</td>
+        <td>Double</td>
+        <td><jsp:setProperty name="values" property="double" 
value="${undefinedFoo}${undefinedBar}"/>${values.double}</td>
+      </tr>
+      <tr>
+        <td>\${undefinedFoo}\${undefinedBar}</td>
+        <td>Double</td>
+        <td><my:values double="${undefinedFoo}${undefinedBar}"/></td>
+      </tr>
+      <tr>
+        <td>\${undefinedFoo}\${undefinedBar}</td>
+        <td>Long</td>
+        <td><jsp:setProperty name="values" property="long" 
value="${undefinedFoo}${undefinedBar}"/>${values.long}</td>
+      </tr>
+      <tr>
+        <td>\${undefinedFoo}\${undefinedBar}</td>
+        <td>Long</td>
+        <td><my:values long="${undefinedFoo}${undefinedBar}"/></td>
+      </tr>
+    </table>
+      </code>
+    </blockquote>
+  </body>
+</html>
+

Propchange: tomcat/trunk/webapps/examples/jsp/jsp2/el/composite.jsp
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to