1 16 package org.apache.cocoon.faces.taglib; 17 18 import org.apache.cocoon.taglib.TagSupport; 19 20 import org.apache.cocoon.faces.FacesUtils; 21 import org.xml.sax.Attributes ; 22 import org.xml.sax.SAXException ; 23 24 import javax.faces.component.EditableValueHolder; 25 import javax.faces.component.UIComponent; 26 import javax.faces.event.ValueChangeListener; 27 28 31 public class ValueChangeListenerTag extends TagSupport { 32 33 private String type; 34 35 public String getType() { 36 return this.type; 37 } 38 39 public void setType(String type) { 40 this.type = type; 41 } 42 43 public int doStartTag(String namespaceURI, String localName, String qName, Attributes atts) 44 throws SAXException { 45 46 UIComponentTag tag = FacesUtils.findParentUIComponentTag(this); 47 if (tag == null) { 48 throw new SAXException ("Tag <" + getClass().getName() + "> have to be nested within a UIComponentTag"); 49 } 50 51 if (!tag.getCreated()) { 52 return 0; 53 } 54 55 UIComponent component = tag.getComponentInstance(); 56 if (component == null) { 57 throw new SAXException ("Parent tag <" + tag.getClass().getName() + "> has no component instance"); 58 } 59 60 if (component instanceof EditableValueHolder) { 61 String clazz = (String ) FacesUtils.evaluate(tag.getFacesContext(), this.type); 62 ValueChangeListener handler = null; 63 try { 64 handler = (ValueChangeListener) Class.forName(clazz).newInstance(); 65 } catch (Exception e) { 66 throw new SAXException ("Tag <" + tag.getClass().getName() + "> could not create action listener <" + clazz + ">", e); 67 } 68 ((EditableValueHolder)component).addValueChangeListener(handler); 69 } 70 71 return SKIP_BODY; 72 } 73 74 public void recycle() { 75 super.recycle(); 76 this.type = null; 77 } 78 } 79 | Popular Tags |