View Javadoc

1   package org.rcfaces.core.internal.taglib;
2   
3   import javax.faces.application.Application;
4   import javax.faces.component.UIComponent;
5   import org.rcfaces.core.internal.component.Properties;
6   import org.rcfaces.core.component.FocusManagerComponent;
7   import javax.el.ValueExpression;
8   import javax.faces.component.UIViewRoot;
9   import org.apache.commons.logging.Log;
10  import javax.servlet.jsp.tagext.Tag;
11  import org.apache.commons.logging.LogFactory;
12  import org.rcfaces.core.internal.tools.ListenersTools1_2;
13  import org.rcfaces.core.internal.tools.ListenersTools;
14  import javax.faces.context.FacesContext;
15  
16  public class FocusManagerTag extends CameliaTag implements Tag {
17  
18  
19  	private static final Log LOG=LogFactory.getLog(FocusManagerTag.class);
20  
21  	private ValueExpression focusId;
22  	private ValueExpression setFocusIfMessage;
23  	public String getComponentType() {
24  		return FocusManagerComponent.COMPONENT_TYPE;
25  	}
26  
27  	public final void setFocusId(ValueExpression focusId) {
28  		this.focusId = focusId;
29  	}
30  
31  	public final void setSetFocusIfMessage(ValueExpression setFocusIfMessage) {
32  		this.setFocusIfMessage = setFocusIfMessage;
33  	}
34  
35  	protected void setProperties(UIComponent uiComponent) {
36  		if (LOG.isDebugEnabled()) {
37  			if (FocusManagerComponent.COMPONENT_TYPE==getComponentType()) {
38  				LOG.debug("Component id='"+getId()+"' type='"+getComponentType()+"'.");
39  			}
40  			LOG.debug("  focusId='"+focusId+"'");
41  			LOG.debug("  setFocusIfMessage='"+setFocusIfMessage+"'");
42  		}
43  		if ((uiComponent instanceof FocusManagerComponent)==false) {
44  			if (uiComponent instanceof UIViewRoot) {
45  				throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
46  			}
47  			throw new IllegalStateException("Component specified by tag is not instanceof of 'FocusManagerComponent'.");
48  		}
49  
50  		super.setProperties(uiComponent);
51  
52  		FocusManagerComponent component = (FocusManagerComponent) uiComponent;
53  		FacesContext facesContext = getFacesContext();
54  
55  		if (focusId != null) {
56  			if (focusId.isLiteralText()==false) {
57  				component.setValueExpression(Properties.FOCUS_ID, focusId);
58  
59  			} else {
60  				component.setFocusId(focusId.getExpressionString());
61  			}
62  		}
63  
64  		if (setFocusIfMessage != null) {
65  			if (setFocusIfMessage.isLiteralText()==false) {
66  				component.setValueExpression(Properties.SET_FOCUS_IF_MESSAGE, setFocusIfMessage);
67  
68  			} else {
69  				component.setSetFocusIfMessage(getBool(setFocusIfMessage.getExpressionString()));
70  			}
71  		}
72  	}
73  
74  	public void release() {
75  		focusId = null;
76  		setFocusIfMessage = null;
77  
78  		super.release();
79  	}
80  
81  }