KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > ListItemTag


1 package fr.improve.struts.taglib.layout;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4 import javax.servlet.jsp.PageContext JavaDoc;
5
6 import fr.improve.struts.taglib.layout.event.EndLayoutEvent;
7 import fr.improve.struts.taglib.layout.event.LayoutEventListener;
8 import fr.improve.struts.taglib.layout.event.StartLayoutEvent;
9 import fr.improve.struts.taglib.layout.util.TagUtils;
10
11 /**
12  * LI tag for Struts-Layout.
13  * This tag is both a message tag and a column tag.
14  *
15  * @author JN Ribette
16  */

17 public class ListItemTag extends LabelledTag implements LayoutEventListener {
18     protected boolean hasContent;
19     
20     /**
21      * Start of custom tag. Display the label if there is one.
22      */

23     public int doStartLayoutTag() throws JspException JavaDoc {
24         new StartLayoutEvent(this, "<td>").send();
25         
26         if (key!=null) {
27             TagUtils.write(pageContext, "<p");
28             if (styleClass!=null) {
29                 TagUtils.write(pageContext, " class=\"");
30                 TagUtils.write(pageContext, styleClass);
31                 TagUtils.write(pageContext, "\">");
32             }
33             TagUtils.write(pageContext, getLabel());
34             TagUtils.write(pageContext, "</p>");
35         }
36         
37         hasContent = false;
38         
39         return EVAL_BODY_INCLUDE;
40     }
41     
42     public Object JavaDoc processEndLayoutEvent(EndLayoutEvent in_event)
43             throws JspException JavaDoc {
44         return in_event.consume(pageContext, "</tr>");
45     }
46
47     public Object JavaDoc processStartLayoutEvent(StartLayoutEvent in_event)
48             throws JspException JavaDoc {
49         if (!hasContent) {
50             hasContent = true;
51             startContent(in_event.getSource().getPageContext());
52         }
53         return in_event.consume(pageContext, "<tr>");
54     }
55     
56     protected void startContent(PageContext JavaDoc pageContext) throws JspException JavaDoc {
57         TagUtils.write(pageContext, "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
58     }
59     
60     protected void endContent(PageContext JavaDoc pageContext) throws JspException JavaDoc {
61         TagUtils.write(pageContext, "</table>");
62     }
63     
64     /**
65      * End of custom tag. Close all opened HTML tags.
66      */

67     public int doEndLayoutTag() throws JspException JavaDoc {
68         if (hasContent) {
69             endContent(pageContext);
70         }
71         
72         new EndLayoutEvent(this, "</td>").send();
73         return EVAL_PAGE;
74     }
75 }
76
Popular Tags