1 16 package org.apache.myfaces.wap.base; 17 18 import javax.faces.component.ActionSource; 19 import javax.faces.component.UIComponent; 20 import javax.faces.context.FacesContext; 21 import javax.faces.el.MethodBinding; 22 import javax.faces.el.ValueBinding; 23 import javax.faces.event.ActionEvent; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 28 42 public abstract class ActionSourceTagBase extends ComponentTagBase { 43 private static Log log = LogFactory.getLog(ActionSourceTagBase.class); 44 45 46 private String action = null; 47 private String actionListener = null; 48 private String immediate = null; 49 50 51 public ActionSourceTagBase() { 52 super(); 53 } 54 55 public abstract String getRendererType(); 56 57 public void release() { 58 super.release(); 59 this.action = null; 60 this.actionListener = null; 61 this.immediate = null; 62 } 63 64 protected void setProperties(UIComponent component) { 65 super.setProperties(component); 66 67 Class [] mbParams = {ActionEvent.class}; 68 69 if (action != null) { 70 if (!(component instanceof ActionSource)) { 71 throw new IllegalArgumentException ("Component " + component.getId() + " is no ActionSource, cannot set 'action' attribute."); 72 } 73 MethodBinding mb; 74 if (isValueReference(action)) 75 mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding(action, null); 76 else 77 mb = new ConstantMethodBinding(action); 78 79 ((ActionSource)component).setAction(mb); 80 } 81 82 if (actionListener != null) { 83 if (!(component instanceof ActionSource)) { 84 throw new IllegalArgumentException ("Component " + component.getId() + " is no ActionSource, cannot set 'actionListener' attribute."); 85 } 86 if (isValueReference(actionListener)) { 87 MethodBinding mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding(actionListener, mbParams); 88 ((ActionSource)component).setActionListener(mb); 89 } 90 else { 91 log.error("Invalid expression " + actionListener); 92 } 93 } 94 95 if (immediate != null) { 96 if (component instanceof ActionSource) { 97 if (isValueReference(immediate)) { 98 ValueBinding vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(immediate); 99 component.setValueBinding("immediate", vb); 100 } 101 else { 102 Boolean imm = Boolean.valueOf(immediate); 103 ((ActionSource)component).setImmediate(imm.booleanValue()); 104 } 105 106 } 107 else log.error("Component " + component.getClass().getName() + " is no ActionSource, cannot set 'immediate' attribute."); 108 } 109 } 110 111 public String getAction() { 113 return action; 114 } 115 116 public void setAction(String action) { 117 this.action = action; 118 } 119 120 public String getActionListener() { 121 return actionListener; 122 } 123 124 public void setActionListener(String actionListener) { 125 this.actionListener = actionListener; 126 } 127 128 132 public String getImmediate() { 133 return immediate; 134 } 135 136 140 public void setImmediate(String immediate) { 141 this.immediate = immediate; 142 } 143 } 144 | Popular Tags |