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 javax.el.ValueExpression;
7   import javax.faces.component.UIViewRoot;
8   import org.apache.commons.logging.Log;
9   import org.rcfaces.core.component.ScopeComponent;
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 ScopeTag extends CameliaTag implements Tag {
17  
18  
19  	private static final Log LOG=LogFactory.getLog(ScopeTag.class);
20  
21  	private ValueExpression scopeSaveValue;
22  	private ValueExpression scopeValue;
23  	private ValueExpression scopeVar;
24  	public String getComponentType() {
25  		return ScopeComponent.COMPONENT_TYPE;
26  	}
27  
28  	public final void setScopeSaveValue(ValueExpression scopeSaveValue) {
29  		this.scopeSaveValue = scopeSaveValue;
30  	}
31  
32  	public final void setScopeValue(ValueExpression scopeValue) {
33  		this.scopeValue = scopeValue;
34  	}
35  
36  	public final void setScopeVar(ValueExpression scopeVar) {
37  		this.scopeVar = scopeVar;
38  	}
39  
40  	protected void setProperties(UIComponent uiComponent) {
41  		if (LOG.isDebugEnabled()) {
42  			if (ScopeComponent.COMPONENT_TYPE==getComponentType()) {
43  				LOG.debug("Component id='"+getId()+"' type='"+getComponentType()+"'.");
44  			}
45  			LOG.debug("  scopeSaveValue='"+scopeSaveValue+"'");
46  			LOG.debug("  scopeValue='"+scopeValue+"'");
47  			LOG.debug("  scopeVar='"+scopeVar+"'");
48  		}
49  		if ((uiComponent instanceof ScopeComponent)==false) {
50  			if (uiComponent instanceof UIViewRoot) {
51  				throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
52  			}
53  			throw new IllegalStateException("Component specified by tag is not instanceof of 'ScopeComponent'.");
54  		}
55  
56  		super.setProperties(uiComponent);
57  
58  		ScopeComponent component = (ScopeComponent) uiComponent;
59  		FacesContext facesContext = getFacesContext();
60  
61  		if (scopeSaveValue != null) {
62  			if (scopeSaveValue.isLiteralText()==false) {
63  				component.setValueExpression(Properties.SCOPE_SAVE_VALUE, scopeSaveValue);
64  
65  			} else {
66  				component.setScopeSaveValue(getBool(scopeSaveValue.getExpressionString()));
67  			}
68  		}
69  
70  		if (scopeValue != null) {
71  			if (scopeValue.isLiteralText()==false) {
72  				component.setValueExpression(Properties.SCOPE_VALUE, scopeValue);
73  
74  			} else {
75  				component.setScopeValue(scopeValue.getExpressionString());
76  			}
77  		}
78  
79  		if (scopeVar != null) {
80  			if (scopeVar.isLiteralText()==false) {
81  				component.setValueExpression(Properties.SCOPE_VAR, scopeVar);
82  
83  			} else {
84  				component.setScopeVar(scopeVar.getExpressionString());
85  			}
86  		}
87  	}
88  
89  	public void release() {
90  		scopeSaveValue = null;
91  		scopeValue = null;
92  		scopeVar = null;
93  
94  		super.release();
95  	}
96  
97  }