Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JSP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
JSP
What's wrong with my customTag?
Zhang Jones
Greenhorn
Posts: 17
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi all!
I can't find any problem in my project, anyone else can help me find out the fault and offer modify ideas?
Movie
package edu.city.foo; import java.util.ArrayList; import java.util.List; public class Movie { private String name; private String genre; public Movie(String name,String genre) { this.name = name; this.genre = genre; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getGenre() { return genre; } public void setGenre(String genre) { this.genre = genre; } public static void main(String[] args) { Movie movie1 = new Movie("7 day","skill"); Movie movie2 = new Movie("night", "skill"); List movies = new ArrayList(); movies.add(movie1); movies.add(movie2); SimpleTagTest simpleTagTest = new SimpleTagTest(); simpleTagTest.setMovieList(movies); } }
SimpleTagTest
package edu.city.foo; import java.io.IOException; import java.util.Iterator; import java.util.List; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.SimpleTagSupport; public class SimpleTagTest extends SimpleTagSupport { private static final long serialVersionUID = 6714301064023583139L; private List movieList; public void setMovieList(List movieList) { this.movieList = movieList; } @Override public void doTag() throws JspException, IOException { Iterator<Movie> iterator = movieList.iterator(); while (iterator.hasNext()) { Movie movies = (Movie) iterator.next(); getJspContext().setAttribute("movie", movies); getJspBody().invoke(null); } } }
simple.tld
<?xml version="1.0" encoding="UTF-8"?> <taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web- jsptaglibrary_2_0.xsd” version=”2.0"> <tlib-version>1.0</tlib-version> <jsp-version>1.2</jsp-version> <uri>simpleTags</uri> <tag> <description>worst use of a custom tag</description> <name>SimpleTagTest</name> <tag-class>edu.city.foo.SimpleTagTest</tag-class> <body-content>scriptless</body-content> <attribute> <name>movieList</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> </taglib>
useTag.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <%@ taglib uri="simpleTags" prefix="myTags" %> <%@ page import="edu.city.foo.*" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'useTag.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <table> <myTags:SimpleTagTest movieList="${movie}"> <tr> <td>${movie.name}</td> <td>${movie.genre}</td> </tr> </myTags:SimpleTagTest> </table> </body> </html>
customTag
Christophe Verré
Sheriff
Posts: 14691
16
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Before even looking at anything, what is your problem exactly ? An error displayed somewhere ? Nothing displayed ?
Did you check the HTML source ?
[My Blog]
All roads lead to JavaRanch
Zhang Jones
Greenhorn
Posts: 17
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
org.apache.jasper.JasperException: An exception occurred processing
JSP
page /useTag.jsp at line 40
39: <table>
40: <myTags:SimpleTagTest movieList="${movie}">
41: <tr>
42: <td>${movie.name}</td>
43: <td>${movie.genre}</td>
David O'Meara
Rancher
Posts: 13459
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
the object bound to the name "movie" is somehow both a list of items and a single item?
Zhang Jones
Greenhorn
Posts: 17
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
a list of items
David O'Meara
Rancher
Posts: 13459
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
but your tag library then sets the name "movie" to be an item and the JSTL refers to ${movie.name}
It can't be both.
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
I have a trouble in Custom tag and I can't find any mistakes, someone else can help me to find out ?
Tag attributes and the setter method
Help with custom tags
Creating and populating a List of javaBeans in a JSP w/o using scriptlets
Doubt in HFSJ..pg 511 creating simple tag with attribute
More...