KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ajaxanywhere > jsf > ZoneJSFTag


1 package org.ajaxanywhere.jsf;
2
3 import javax.faces.application.Application;
4 import javax.faces.component.UIComponent;
5 import javax.faces.context.FacesContext;
6 import javax.faces.el.ValueBinding;
7 import javax.faces.webapp.UIComponentBodyTag;
8 import javax.faces.webapp.UIComponentTag;
9 import javax.servlet.jsp.JspException JavaDoc;
10 import javax.servlet.jsp.PageContext JavaDoc;
11 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
12 import javax.servlet.jsp.tagext.BodyTag JavaDoc;
13 import javax.servlet.jsp.tagext.Tag JavaDoc;
14
15 /**
16  * @jsp.tag name = "zoneJSF"
17  * display-name = "zoneJSF"
18  * description = ""
19  */

20 public class ZoneJSFTag implements Tag, BodyTag {
21     public String JavaDoc id;
22     private String JavaDoc idSuffix;
23
24     private static final String JavaDoc COMPONENT_TYPE = "org.ajaxanywhere.ZoneUIComponent";
25     private UIComponentBodyTag uiComponentBodyTag;
26
27
28     public ZoneJSFTag() {
29         uiComponentBodyTag = new UIComponentBodyTag() {
30             
31             private String JavaDoc idSuffix;
32             
33             public String JavaDoc getComponentType() {
34                 return COMPONENT_TYPE;
35             }
36
37             public String JavaDoc getRendererType() {
38                 return null;
39             }
40             
41             protected void setProperties(UIComponent component) {
42                 super.setProperties(component);
43                 setValueBindingProperty(component, "idSuffix", idSuffix);
44             }
45             
46             protected UIComponent findComponent(FacesContext context) throws JspException JavaDoc {
47                 return super.findComponent(context);
48             }
49             
50             void setValueBindingProperty(UIComponent component, String JavaDoc attrName, String JavaDoc value)
51             {
52                 if (value==null) return;
53                 
54                 if (!UIComponentTag.isValueReference(value))
55                 {
56                     throw new IllegalArgumentException JavaDoc("idSuffix must be an EL expression!");
57                 }
58                 else
59                 {
60                     component.setValueBinding(attrName, createValueBinding(value));
61                 }
62             }
63             
64             ValueBinding createValueBinding(String JavaDoc value)
65             {
66                 FacesContext ctx = FacesContext.getCurrentInstance();
67                 Application app = ctx.getApplication();
68                 return app.createValueBinding(value);
69             }
70
71             public String JavaDoc getIdSuffix() {
72                 return idSuffix;
73             }
74
75             public void setIdSuffix(String JavaDoc idSuffix) {
76                 this.idSuffix = idSuffix;
77             }
78         };
79     }
80
81     public void release() {
82         id = null;
83         idSuffix = null;
84         uiComponentBodyTag.release();
85     }
86
87     public String JavaDoc getId() {
88         return id;
89     }
90
91     public void setPageContext(PageContext JavaDoc pageContext) {
92         id = null;
93         idSuffix = null;
94         uiComponentBodyTag.setPageContext(pageContext);
95     }
96
97     public Tag getParent() {
98         return uiComponentBodyTag.getParent();
99     }
100
101     public void setParent(Tag parent) {
102         uiComponentBodyTag.setParent(parent);
103     }
104
105     public int doStartTag() throws JspException JavaDoc {
106         return uiComponentBodyTag.doStartTag();
107     }
108
109     public int doEndTag() throws JspException JavaDoc {
110         return uiComponentBodyTag.doEndTag();
111     }
112
113
114     public int doAfterBody() throws JspException JavaDoc {
115         return uiComponentBodyTag.doAfterBody();
116     }
117
118     public void doInitBody() throws JspException JavaDoc {
119         uiComponentBodyTag.doInitBody();
120     }
121
122
123     public void setBodyContent(BodyContent JavaDoc bodyContent) {
124         uiComponentBodyTag.setBodyContent(bodyContent);
125     }
126
127     /**
128      * @param id String
129      * @jsp.attribute required="false"
130      * rtexprvalue="true"
131      * type="java.lang.String"
132      * description="name description"
133      */

134     public void setId(String JavaDoc id) {
135         this.id = id;
136         uiComponentBodyTag.setId(id);
137     }
138
139     public String JavaDoc getIdSuffix() {
140         return idSuffix;
141     }
142
143     /**
144      * @param idSuffix String
145      * @jsp.attribute required="false"
146      * rtexprvalue="true"
147      * type="java.lang.String"
148      * description="the idSuffix can be set to en EL expression, which is appended to the id to form the resulting id of the aazone span html element. This allows to create dynamic zones e.g. in a datatable"
149      */

150     public void setIdSuffix(String JavaDoc idSuffix) {
151         this.idSuffix = idSuffix;
152         try {
153             uiComponentBodyTag.getClass().getMethod("setIdSuffix", new Class JavaDoc[] { String JavaDoc.class }).invoke(uiComponentBodyTag, new Object JavaDoc[] { idSuffix });
154         } catch (Exception JavaDoc e) {
155             IllegalStateException JavaDoc ise = new IllegalStateException JavaDoc("Couldn't invoke setDynamicId on inner class");
156             ise.initCause(e);
157             throw ise;
158         }
159     }
160 }
161
Popular Tags