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 ; 10 import javax.servlet.jsp.PageContext ; 11 import javax.servlet.jsp.tagext.BodyContent ; 12 import javax.servlet.jsp.tagext.BodyTag ; 13 import javax.servlet.jsp.tagext.Tag ; 14 15 20 public class ZoneJSFTag implements Tag, BodyTag { 21 public String id; 22 private String idSuffix; 23 24 private static final String COMPONENT_TYPE = "org.ajaxanywhere.ZoneUIComponent"; 25 private UIComponentBodyTag uiComponentBodyTag; 26 27 28 public ZoneJSFTag() { 29 uiComponentBodyTag = new UIComponentBodyTag() { 30 31 private String idSuffix; 32 33 public String getComponentType() { 34 return COMPONENT_TYPE; 35 } 36 37 public String 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 { 47 return super.findComponent(context); 48 } 49 50 void setValueBindingProperty(UIComponent component, String attrName, String value) 51 { 52 if (value==null) return; 53 54 if (!UIComponentTag.isValueReference(value)) 55 { 56 throw new IllegalArgumentException ("idSuffix must be an EL expression!"); 57 } 58 else 59 { 60 component.setValueBinding(attrName, createValueBinding(value)); 61 } 62 } 63 64 ValueBinding createValueBinding(String value) 65 { 66 FacesContext ctx = FacesContext.getCurrentInstance(); 67 Application app = ctx.getApplication(); 68 return app.createValueBinding(value); 69 } 70 71 public String getIdSuffix() { 72 return idSuffix; 73 } 74 75 public void setIdSuffix(String 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 getId() { 88 return id; 89 } 90 91 public void setPageContext(PageContext 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 { 106 return uiComponentBodyTag.doStartTag(); 107 } 108 109 public int doEndTag() throws JspException { 110 return uiComponentBodyTag.doEndTag(); 111 } 112 113 114 public int doAfterBody() throws JspException { 115 return uiComponentBodyTag.doAfterBody(); 116 } 117 118 public void doInitBody() throws JspException { 119 uiComponentBodyTag.doInitBody(); 120 } 121 122 123 public void setBodyContent(BodyContent bodyContent) { 124 uiComponentBodyTag.setBodyContent(bodyContent); 125 } 126 127 134 public void setId(String id) { 135 this.id = id; 136 uiComponentBodyTag.setId(id); 137 } 138 139 public String getIdSuffix() { 140 return idSuffix; 141 } 142 143 150 public void setIdSuffix(String idSuffix) { 151 this.idSuffix = idSuffix; 152 try { 153 uiComponentBodyTag.getClass().getMethod("setIdSuffix", new Class [] { String .class }).invoke(uiComponentBodyTag, new Object [] { idSuffix }); 154 } catch (Exception e) { 155 IllegalStateException ise = new IllegalStateException ("Couldn't invoke setDynamicId on inner class"); 156 ise.initCause(e); 157 throw ise; 158 } 159 } 160 } 161 | Popular Tags |