1 16 package org.apache.myfaces.custom.updateactionlistener; 17 18 import javax.faces.application.Application; 19 import javax.faces.component.ActionSource; 20 import javax.faces.component.UIComponent; 21 import javax.faces.context.FacesContext; 22 import javax.faces.convert.Converter; 23 import javax.faces.webapp.UIComponentTag; 24 import javax.servlet.jsp.JspException ; 25 import javax.servlet.jsp.tagext.Tag ; 26 import javax.servlet.jsp.tagext.TagSupport ; 27 28 42 public class UpdateActionListenerTag 43 extends TagSupport 44 { 45 47 private String _property; 48 private String _value; 49 private String _converter; 50 51 public UpdateActionListenerTag() 52 { 53 } 54 55 public void setProperty(String property) 56 { 57 _property = property; 58 } 59 60 public void setValue(String value) 61 { 62 _value = value; 63 } 64 65 public void setConverter(String converter) 66 { 67 _converter = converter; 68 } 69 70 public int doStartTag() throws JspException 71 { 72 if (_property == null) throw new JspException ("property attribute not set"); 73 if (_value == null) throw new JspException ("value attribute not set"); 74 if (!UIComponentTag.isValueReference(_property)) throw new JspException ("property attribute is no valid value reference: " + _property); 75 76 UIComponentTag componentTag = UIComponentTag.getParentUIComponentTag(pageContext); 78 if (componentTag == null) 79 { 80 throw new JspException ("UpdateActionListenerTag has no UIComponentTag ancestor"); 81 } 82 83 if (componentTag.getCreated()) 84 { 85 UIComponent component = componentTag.getComponentInstance(); 87 if (component instanceof ActionSource) 88 { 89 FacesContext facesContext = FacesContext.getCurrentInstance(); 90 Application application = facesContext.getApplication(); 91 UpdateActionListener al = new UpdateActionListener(); 92 al.setPropertyBinding(application.createValueBinding(_property)); 93 if (UIComponentTag.isValueReference(_value)) 94 { 95 al.setValueBinding(application.createValueBinding(_value)); 96 } 97 else 98 { 99 al.setValue(_value); 100 } 101 if (_converter != null) 102 { 103 Converter converter = application.createConverter(_converter); 104 al.setConverter(converter); 105 } 106 ((ActionSource)component).addActionListener(al); 107 } 108 else 109 { 110 throw new JspException ("Component " + component.getId() + " is no ActionSource"); 111 } 112 } 113 114 return Tag.SKIP_BODY; 115 } 116 } 117 | Popular Tags |