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.ButtonComponent;
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 ButtonTag extends AbstractCommandTag implements Tag {
17  
18  
19  	private static final Log LOG=LogFactory.getLog(ButtonTag.class);
20  
21  	private ValueExpression text;
22  	private ValueExpression textDirection;
23  	private ValueExpression selectionListeners;
24  	private ValueExpression readOnly;
25  	private ValueExpression alternateText;
26  	private ValueExpression focusStyleClass;
27  	private ValueExpression actionListeners;
28  	private ValueExpression action;
29  	public String getComponentType() {
30  		return ButtonComponent.COMPONENT_TYPE;
31  	}
32  
33  	public final void setText(ValueExpression text) {
34  		this.text = text;
35  	}
36  
37  	public final void setTextDirection(ValueExpression textDirection) {
38  		this.textDirection = textDirection;
39  	}
40  
41  	public final void setSelectionListener(ValueExpression selectionListeners) {
42  		this.selectionListeners = selectionListeners;
43  	}
44  
45  	public final void setReadOnly(ValueExpression readOnly) {
46  		this.readOnly = readOnly;
47  	}
48  
49  	public final void setAlternateText(ValueExpression alternateText) {
50  		this.alternateText = alternateText;
51  	}
52  
53  	public final void setFocusStyleClass(ValueExpression focusStyleClass) {
54  		this.focusStyleClass = focusStyleClass;
55  	}
56  
57  	public final void setAction(ValueExpression action) {
58  		this.action=action;
59  	}
60  
61  	public final void setActionListener(ValueExpression listeners) {
62  		this.actionListeners = listeners;
63  	}
64  
65  	protected void setProperties(UIComponent uiComponent) {
66  		if (LOG.isDebugEnabled()) {
67  			if (ButtonComponent.COMPONENT_TYPE==getComponentType()) {
68  				LOG.debug("Component id='"+getId()+"' type='"+getComponentType()+"'.");
69  			}
70  			LOG.debug("  text='"+text+"'");
71  			LOG.debug("  textDirection='"+textDirection+"'");
72  			LOG.debug("  readOnly='"+readOnly+"'");
73  			LOG.debug("  alternateText='"+alternateText+"'");
74  			LOG.debug("  focusStyleClass='"+focusStyleClass+"'");
75  			LOG.debug("  action='"+action+"'");
76  			LOG.debug("  actionListeners='"+actionListeners+"'");
77  		}
78  		if ((uiComponent instanceof ButtonComponent)==false) {
79  			if (uiComponent instanceof UIViewRoot) {
80  				throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
81  			}
82  			throw new IllegalStateException("Component specified by tag is not instanceof of 'ButtonComponent'.");
83  		}
84  
85  		super.setProperties(uiComponent);
86  
87  		ButtonComponent component = (ButtonComponent) uiComponent;
88  		FacesContext facesContext = getFacesContext();
89  
90  		if (text != null) {
91  			if (text.isLiteralText()==false) {
92  				component.setValueExpression(Properties.TEXT, text);
93  
94  			} else {
95  				component.setText(text.getExpressionString());
96  			}
97  		}
98  
99  		if (textDirection != null) {
100 			if (textDirection.isLiteralText()==false) {
101 				component.setValueExpression(Properties.TEXT_DIRECTION, textDirection);
102 
103 			} else {
104 				component.setTextDirection(getInt(textDirection.getExpressionString()));
105 			}
106 		}
107 
108 		if (selectionListeners != null) {
109 			ListenersTools1_2.parseListener(facesContext, component, ListenersTools.SELECTION_LISTENER_TYPE, selectionListeners);
110 		}
111 
112 		if (readOnly != null) {
113 			if (readOnly.isLiteralText()==false) {
114 				component.setValueExpression(Properties.READ_ONLY, readOnly);
115 
116 			} else {
117 				component.setReadOnly(getBool(readOnly.getExpressionString()));
118 			}
119 		}
120 
121 		if (alternateText != null) {
122 			if (alternateText.isLiteralText()==false) {
123 				component.setValueExpression(Properties.ALTERNATE_TEXT, alternateText);
124 
125 			} else {
126 				component.setAlternateText(alternateText.getExpressionString());
127 			}
128 		}
129 
130 		if (focusStyleClass != null) {
131 			if (focusStyleClass.isLiteralText()==false) {
132 				component.setValueExpression(Properties.FOCUS_STYLE_CLASS, focusStyleClass);
133 
134 			} else {
135 				component.setFocusStyleClass(focusStyleClass.getExpressionString());
136 			}
137 		}
138 
139 		if (action != null) {
140 			ListenersTools1_2.parseAction(facesContext, component, ListenersTools.SELECTION_LISTENER_TYPE, action);
141 		}
142 
143 		if (actionListeners != null) {
144 			ListenersTools1_2.parseListener(facesContext, component, ListenersTools.SELECTION_LISTENER_TYPE, actionListeners, true);
145 		}
146 	}
147 
148 	public void release() {
149 		text = null;
150 		textDirection = null;
151 		selectionListeners = null;
152 		readOnly = null;
153 		alternateText = null;
154 		focusStyleClass = null;
155 		action = null;
156 		actionListeners = null;
157 
158 		super.release();
159 	}
160 
161 }