You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Hiroshi Iwatani <HG...@nifty.ne.jp> on 2004/06/28 00:32:34 UTC
Tag handler can't evaluate EL
Tomcat 5.0.19 can run the following tag, but can't assgin or evaluate values
to/from EL variable. So, Tomcat output is:
${a1}
${a1}
${a1}
while expected output is:
a
b
c
Resin and JRun can do the expected behavior.
---tag handler------------------------------------------------------------
package mytag;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import javax.servlet.http.*;
import java.util.*;
public class foreach extends BodyTagSupport{
private Iterator iterator;
private String group;
public void setGroup(String group){
this.group = group;
}
public String getGroup(){
return group;
}
public int doStartTag() throws JspException{
try{
String[] intarray = new String[] {"a","b","c"};
ArrayList ar = new ArrayList(Arrays.asList(intarray));
iterator = ar.iterator();
if (iterator.hasNext()){
String o = (String)iterator.next();
pageContext.setAttribute("a1", o);
return EVAL_BODY_BUFFERED;
}
else{
return SKIP_BODY;
}
}
catch (Exception e){
System.err.println(e);
}
return SKIP_BODY;
}
public int doAfterBody() throws JspException{
try{
if (iterator == null){
return SKIP_BODY;
}
if (iterator.hasNext()) {
String o = (String)iterator.next();
pageContext.setAttribute("a1", o);
return EVAL_BODY_AGAIN;
}
else{
return SKIP_BODY;
}
}
catch (Exception e){
System.err.println(e);
}
return SKIP_BODY;
}
public int doEndTag() throws JspException {
try {
pageContext.getOut().print(bodyContent.getString());
}
catch(Exception ioe) {
System.out.println(ioe);
}
return EVAL_PAGE;
}
}
--test.jsp-----------------------------------------------------------
<%@ page contentType="text/html" %>
<%@ taglib prefix="jrun" uri="/WEB-INF/mytag.tld" %>
<html><body bgcolor="lightgreen">
<hr>
[Tag Test]<br>
<jrun:foreach group="itemsql">
${a1}<br>
</jrun:foreach>
<hr>
This is another test<br>
<jrun:foreach group="itemsql">
${a1}<br>
</jrun:foreach>
<hr>
This bad boy!<br>
<jrun:foreach group="itemsql">
${a1}<br>
</jrun:foreach>
<hr></body></html>
--TLD----------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<tag>
<name>foreach</name>
<tag-class>mytag.foreach</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>group</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
-----------------------------------------------------------------
--
Hiroshi Iwatani
*stop cruelty* Annual number of institutionally euthanized cats and dogs
including kittens and puppies: US 5 million, JP 500 thousand. How about your
country? *for our better karma*
---------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org