Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJWCD
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Eclipse Collections Categorically: Level up your programming game
this week in the
Open Source Projects
forum!
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:
Campbell Ritchie
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Web Component Certification (OCEJWCD)
Coding tag handlers or tag files together
Bob CHOI
Ranch Hand
Posts: 127
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Below are my tag handler code snippets on a very-simple-nested-tags-example in "classic" style.
Hopefully you can also post yours in "simple" style or "tag file" style, so that we can learn writing tag handlers or tag files more quickly together.
Hard work rewards
Bob CHOI
Ranch Hand
Posts: 127
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
jsp
<%@ taglib uri="http://my-tag-world.com" prefix="nested" %> <nested :-o uter outerAttributeName="abc"> <nested:inner innerAttributeName="xyz">new text</nested:inner> </nested :-o uter> <nested :-o uter outerAttributeName="123"> <nested:inner innerAttributeName="123">new text</nested:inner> </nested :-o uter>
Hard work rewards
Bob CHOI
Ranch Hand
Posts: 127
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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> <uri>http://my-tag-world.com</uri> <tag> <name>outer</name> <tag-class>p.OuterTag</tag-class> <body-content>JSP</body-content> <attribute> <name>outerAttributeName</name> <required>true</required> </attribute> </tag> <tag> <name>inner</name> <tag-class>p.InnerTag</tag-class> <body-content>JSP</body-content> <attribute> <name>innerAttributeName</name> <required>true</required> </attribute> </tag> </taglib>
Hard work rewards
Bob CHOI
Ranch Hand
Posts: 127
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
tag handler class OuterTag
package p; import java.util.*; import java.io.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; public class OuterTag extends TagSupport { private PageContext pc; //Step 1 public void setPageContext(PageContext pc) { this.pc = pc; setValue("outerTextName", "default text"); } //Step 2 public void setOuterAttributeName(String outerAttributeValue){ setValue("outerAttributeName", outerAttributeValue); } //Step 3 public int doStartTag() throws JspException { return EVAL_BODY_INCLUDE; } //Step 8 public int doEndTag() throws JspException { try { JspWriter jw = pc.getOut(); Object outerTextValue = getValue("outerTextName"); jw.println(outerTextValue + "<p>"); } catch (Exception e) { System.out.println("OuterTag: " + e); } return EVAL_PAGE; } }
Hard work rewards
Bob CHOI
Ranch Hand
Posts: 127
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
tag hanlder class InnerTag
package p; import java.util.*; import java.io.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; public class InnerTag extends BodyTagSupport { private OuterTag ot; private BodyContent bc; //Step 4 public void setInnerAttributeName(String value) { setValue("innerAttributeName", value); } //Step 5 public int doStartTag() throws JspException { ot = (OuterTag)findAncestorWithClass(this, OuterTag.class); //ot = (OuterTag)getParent(); //convenience mothod to above Object innerAttributeValue = getValue("innerAttributeName"); Object outerAttributeValue = ot.getValue("outerAttributeName"); if (innerAttributeValue.equals(outerAttributeValue)) return EVAL_BODY_BUFFERED; else return SKIP_BODY; } //Step 6 public void setBodyContent(BodyContent bc) { this.bc = bc; } //Step 7 public int doAfterBody() throws JspException { try { String innerTextValue = bc.getString(); ot.setValue("outerTextName", innerTextValue); } catch (Exception e) { System.out.println("InnerTag: " + e); } return SKIP_BODY; } }
[ January 12, 2007: Message edited by: Bob CHOI ]
[ January 12, 2007: Message edited by: Bob CHOI ]
Hard work rewards
Bob CHOI
Ranch Hand
Posts: 127
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
output:
default text
new text
Hard work rewards
New rule: no elephants at the chess tournament. Tiny ads are still okay.
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
tagfiles and scriptlets
So where are scriptlets never allowed?
Classsic Vs Simple?
.tag file - nested tags
Container generated tld files - only for tag files?
More...