View Javadoc

1   package org.rcfaces.core.internal.taglib;
2   
3   import javax.faces.application.Application;
4   import org.rcfaces.core.component.CustomButtonComponent;
5   import javax.faces.component.UIComponent;
6   import org.rcfaces.core.internal.component.Properties;
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 CustomButtonTag extends AbstractCommandTag implements Tag {
17  
18  
19  	private static final Log LOG=LogFactory.getLog(CustomButtonTag.class);
20  
21  	private ValueExpression borderType;
22  	private ValueExpression border;
23  	private ValueExpression selectionListeners;
24  	private ValueExpression doubleClickListeners;
25  	private ValueExpression readOnly;
26  	private ValueExpression actionListeners;
27  	private ValueExpression action;
28  	public String getComponentType() {
29  		return CustomButtonComponent.COMPONENT_TYPE;
30  	}
31  
32  	public final void setBorderType(ValueExpression borderType) {
33  		this.borderType = borderType;
34  	}
35  
36  	public final void setBorder(ValueExpression border) {
37  		this.border = border;
38  	}
39  
40  	public final void setSelectionListener(ValueExpression selectionListeners) {
41  		this.selectionListeners = selectionListeners;
42  	}
43  
44  	public final void setDoubleClickListener(ValueExpression doubleClickListeners) {
45  		this.doubleClickListeners = doubleClickListeners;
46  	}
47  
48  	public final void setReadOnly(ValueExpression readOnly) {
49  		this.readOnly = readOnly;
50  	}
51  
52  	public final void setAction(ValueExpression action) {
53  		this.action=action;
54  	}
55  
56  	public final void setActionListener(ValueExpression listeners) {
57  		this.actionListeners = listeners;
58  	}
59  
60  	protected void setProperties(UIComponent uiComponent) {
61  		if (LOG.isDebugEnabled()) {
62  			if (CustomButtonComponent.COMPONENT_TYPE==getComponentType()) {
63  				LOG.debug("Component id='"+getId()+"' type='"+getComponentType()+"'.");
64  			}
65  			LOG.debug("  borderType='"+borderType+"'");
66  			LOG.debug("  border='"+border+"'");
67  			LOG.debug("  readOnly='"+readOnly+"'");
68  			LOG.debug("  action='"+action+"'");
69  			LOG.debug("  actionListeners='"+actionListeners+"'");
70  		}
71  		if ((uiComponent instanceof CustomButtonComponent)==false) {
72  			if (uiComponent instanceof UIViewRoot) {
73  				throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
74  			}
75  			throw new IllegalStateException("Component specified by tag is not instanceof of 'CustomButtonComponent'.");
76  		}
77  
78  		super.setProperties(uiComponent);
79  
80  		CustomButtonComponent component = (CustomButtonComponent) uiComponent;
81  		FacesContext facesContext = getFacesContext();
82  
83  		if (borderType != null) {
84  			if (borderType.isLiteralText()==false) {
85  				component.setValueExpression(Properties.BORDER_TYPE, borderType);
86  
87  			} else {
88  				component.setBorderType(borderType.getExpressionString());
89  			}
90  		}
91  
92  		if (border != null) {
93  			if (border.isLiteralText()==false) {
94  				component.setValueExpression(Properties.BORDER, border);
95  
96  			} else {
97  				component.setBorder(getBool(border.getExpressionString()));
98  			}
99  		}
100 
101 		if (selectionListeners != null) {
102 			ListenersTools1_2.parseListener(facesContext, component, ListenersTools.SELECTION_LISTENER_TYPE, selectionListeners);
103 		}
104 
105 		if (doubleClickListeners != null) {
106 			ListenersTools1_2.parseListener(facesContext, component, ListenersTools.DOUBLE_CLICK_LISTENER_TYPE, doubleClickListeners);
107 		}
108 
109 		if (readOnly != null) {
110 			if (readOnly.isLiteralText()==false) {
111 				component.setValueExpression(Properties.READ_ONLY, readOnly);
112 
113 			} else {
114 				component.setReadOnly(getBool(readOnly.getExpressionString()));
115 			}
116 		}
117 
118 		if (action != null) {
119 			ListenersTools1_2.parseAction(facesContext, component, ListenersTools.SELECTION_LISTENER_TYPE, action);
120 		}
121 
122 		if (actionListeners != null) {
123 			ListenersTools1_2.parseListener(facesContext, component, ListenersTools.SELECTION_LISTENER_TYPE, actionListeners, true);
124 		}
125 	}
126 
127 	public void release() {
128 		borderType = null;
129 		border = null;
130 		selectionListeners = null;
131 		doubleClickListeners = null;
132 		readOnly = null;
133 		action = null;
134 		actionListeners = null;
135 
136 		super.release();
137 	}
138 
139 }