1 /* 2 * $Id: ActionSource.java,v 1.16 2007/04/27 22:00:03 ofung Exp $ 3 */ 4 5 /* 6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 7 * 8 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. 9 * 10 * The contents of this file are subject to the terms of either the GNU 11 * General Public License Version 2 only ("GPL") or the Common Development 12 * and Distribution License("CDDL") (collectively, the "License"). You 13 * may not use this file except in compliance with the License. You can obtain 14 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html 15 * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific 16 * language governing permissions and limitations under the License. 17 * 18 * When distributing the software, include this License Header Notice in each 19 * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt. 20 * Sun designates this particular file as subject to the "Classpath" exception 21 * as provided by Sun in the GPL Version 2 section of the License file that 22 * accompanied this code. If applicable, add the following below the License 23 * Header, with the fields enclosed by brackets [] replaced by your own 24 * identifying information: "Portions Copyrighted [year] 25 * [name of copyright owner]" 26 * 27 * Contributor(s): 28 * 29 * If you wish your version of this file to be governed by only the CDDL or 30 * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 * elects to include this software in this distribution under the [CDDL or GPL 32 * Version 2] license." If you don't indicate a single choice of license, a 33 * recipient has the option to distribute your version of this file under 34 * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 * its licensees as provided above. However, if you add GPL Version 2 code 36 * and therefore, elected the GPL Version 2 license, then the option applies 37 * only if the new code is made subject to such option by the copyright 38 * holder. 39 */ 40 41 package javax.faces.component; 42 43 44 import javax.faces.event.ActionEvent; 45 import javax.faces.event.ActionListener; 46 import javax.faces.el.MethodBinding; 47 48 49 50 /** 51 * <p><strong>ActionSource</strong> is an interface that may be implemented 52 * by any concrete {@link UIComponent} that wishes to be a source of 53 * {@link ActionEvent}s, including the ability to invoke application 54 * actions via the default {@link ActionListener} mechanism.</p> 55 */ 56 57 public interface ActionSource { 58 59 60 // -------------------------------------------------------------- Properties 61 62 63 /** 64 * <p>If the implementing class also implements {@link 65 * ActionSource2}, the implementation of this method must call 66 * through to {@link ActionSource2#getActionExpression} and examine 67 * the result. If the result came from a previous call to {@link 68 * #setAction}, extract the <code>MethodBinding</code> from it and 69 * return it. Otherwise, wrap the returned {@link 70 * javax.el.MethodExpression} in a <code>MethodBinding</code> 71 * implementation, and return it.</p> 72 * 73 * <p>If the implementing class does not implement 74 * <code>ActionSource2</code>, return the {@link 75 * MethodBinding}pointing at the application action to be invoked, 76 * if this {@link UIComponent} is activated by the user, during the 77 * <em>Apply Request Values</em> or <em>Invoke Application</em> 78 * phase of the request processing lifecycle, depending on the value 79 * of the <code>immediate</code> property.</p> 80 * 81 * @deprecated This has been replaced by {@link 82 * ActionSource2#getActionExpression}. 83 */ 84 public MethodBinding getAction(); 85 86 /** 87 * <p>If the implementing class also implements {@link 88 * ActionSource2}, the implementation of this method must wrap the 89 * argument <code>action</code> in a class that implements {@link 90 * javax.el.MethodExpression} and call through to {@link 91 * ActionSource2#setActionExpression}, passing the wrapped 92 * <code>action</code>.</p> 93 * 94 * <p>If the implementing class does not implement 95 * <code>ActionSource2</code>, set the {@link MethodBinding} 96 * pointing at the appication action to be invoked, if this {@link 97 * UIComponent} is activated by the user, during the <em>Apply 98 * Request Values</em> or <em>Invoke Application</em> phase of the 99 * request processing lifecycle, depending on the value of the 100 * <code>immediate</code> property.</p> 101 * 102 * <p>Any method referenced by such an expression must be public, with 103 * a return type of <code>String</code>, and accept no parameters.</p> 104 * 105 * @param action The new MethodBinding expression 106 * 107 * @deprecated This has been replaced by {@link 108 * ActionSource2#setActionExpression(javax.el.MethodExpression)}. 109 */ 110 public void setAction(MethodBinding action); 111 112 113 /** 114 * <p>If {@link #setActionListener} was not previously called 115 * for this instance, this method must return <code>null</code>. If 116 * it was called, this method must return the exact 117 * <code>MethodBinding</code> instance that was passed to {@link 118 * #setActionListener}.</p> 119 * 120 * <p> The method to be invoked, if this {@link UIComponent} is 121 * activated by the user, will be called during the <em>Apply 122 * Request Values</em> or <em>Invoke Application</em> phase of the 123 * request processing lifecycle, depending upon the value of the 124 * <code>immediate</code> property.</p> 125 * 126 * @deprecated Use {@link #getActionListeners} instead. 127 */ 128 public MethodBinding getActionListener(); 129 130 131 /** 132 * <p>Wrap the argument <code>actionListener</code> in an 133 * implementation of {@link ActionListener} 134 * and store it in the internal data structure that backs the {@link 135 * #getActionListeners} method, taking care to over-write any 136 * instance that was stored by a previous call to 137 * <code>setActionListener</code>.</p> 138 * 139 * <p>Any method referenced by such an expression must be public, with 140 * a return type of <code>void</code>, and accept a single parameter of 141 * type <code>ActionEvent</code>.</p> 142 * 143 * @param actionListener The new method binding expression 144 * 145 * @deprecated This has been replaced by {@link 146 * #addActionListener(javax.faces.event.ActionListener)}. 147 */ 148 public void setActionListener(MethodBinding actionListener); 149 150 /** 151 * <p>Return a flag indicating that the default {@link ActionListener} 152 * provided by the JavaServer Faces implementation should be executed 153 * immediately (that is, during <em>Apply Request Values</em> phase 154 * of the request processing lifecycle), rather than waiting until the 155 * <em>Invoke Application</em> phase. The default value for this 156 * property must be <code>false</code>.</p> 157 */ 158 public boolean isImmediate(); 159 160 161 /** 162 * <p>Set the "immediate execution" flag for this {@link UIComponent}.</p> 163 * 164 * @param immediate The new immediate execution flag 165 */ 166 public void setImmediate(boolean immediate); 167 168 169 // -------------------------------------------------- Event Listener Methods 170 171 172 /** 173 * <p>Add a new {@link ActionListener} to the set of listeners interested 174 * in being notified when {@link ActionEvent}s occur.</p> 175 * 176 * @param listener The {@link ActionListener} to be added 177 * 178 * @throws NullPointerException if <code>listener</code> 179 * is <code>null</code> 180 */ 181 public void addActionListener(ActionListener listener); 182 183 184 /** 185 * <p>Return the set of registered {@link ActionListener}s for this 186 * {@link ActionSource} instance. If there are no registered listeners, 187 * a zero-length array is returned.</p> 188 */ 189 public abstract ActionListener[] getActionListeners(); 190 191 192 /** 193 * <p>Remove an existing {@link ActionListener} (if any) from the set of 194 * listeners interested in being notified when {@link ActionEvent}s 195 * occur.</p> 196 * 197 * @param listener The {@link ActionListener} to be removed 198 * 199 * @throws NullPointerException if <code>listener</code> 200 * is <code>null</code> 201 */ 202 public void removeActionListener(ActionListener listener); 203 204 205 }