001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.taglib.aui;
016    
017    import com.liferay.portal.kernel.util.Validator;
018    import com.liferay.taglib.util.IncludeTag;
019    import com.liferay.util.TextFormatter;
020    
021    import java.util.Map;
022    
023    import javax.servlet.http.HttpServletRequest;
024    
025    /**
026     * @author Julio Camarero
027     * @author Jorge Ferrer
028     * @author Brian Wing Shun Chan
029     */
030    public class SelectTag extends IncludeTag {
031    
032            public void setBean(Object bean) {
033                    _bean = bean;
034            }
035    
036            public void setChangesContext(boolean changesContext) {
037                    _changesContext = changesContext;
038            }
039    
040            public void setCssClass(String cssClass) {
041                    _cssClass = cssClass;
042            }
043    
044            public void setData(Map<String,Object> data) {
045                    _data = data;
046            }
047    
048            public void setDisabled(boolean disabled) {
049                    _disabled = disabled;
050            }
051    
052            public void setFirst(boolean first) {
053                    _first = first;
054            }
055    
056            public void setHelpMessage(String helpMessage) {
057                    _helpMessage = helpMessage;
058            }
059    
060            public void setId(String id) {
061                    _id = id;
062            }
063    
064            public void setInlineField(boolean inlineField) {
065                    _inlineField = inlineField;
066            }
067    
068            public void setInlineLabel(String inlineLabel) {
069                    _inlineLabel = inlineLabel;
070            }
071    
072            public void setInputCssClass(String inputCssClass) {
073                    _inputCssClass = inputCssClass;
074            }
075    
076            public void setLabel(String label) {
077                    _label = label;
078            }
079    
080            public void setLast(boolean last) {
081                    _last = last;
082            }
083    
084            public void setListType(String listType) {
085                    _listType = listType;
086            }
087    
088            public void setListTypeFieldName(String listTypeFieldName) {
089                    _listTypeFieldName = listTypeFieldName;
090            }
091    
092            public void setMultiple(boolean multiple) {
093                    _multiple = multiple;
094            }
095    
096            public void setName(String name) {
097                    _name = name;
098            }
099    
100            public void setOnChange(String onChange) {
101                    _onChange = onChange;
102            }
103    
104            public void setOnClick(String onClick) {
105                    _onClick = onClick;
106            }
107    
108            public void setPrefix(String prefix) {
109                    _prefix = prefix;
110            }
111    
112            public void setShowEmptyOption(boolean showEmptyOption) {
113                    _showEmptyOption = showEmptyOption;
114            }
115    
116            public void setTitle(String title) {
117                    _title = title;
118            }
119    
120            public void setSuffix(String suffix) {
121                    _suffix = suffix;
122            }
123    
124            protected void cleanUp() {
125                    _bean = null;
126                    _changesContext = false;
127                    _cssClass = null;
128                    _data = null;
129                    _first = false;
130                    _helpMessage = null;
131                    _inlineField = false;
132                    _inlineLabel = null;
133                    _inputCssClass = null;
134                    _id = null;
135                    _label = null;
136                    _last = false;
137                    _listType = null;
138                    _listTypeFieldName = null;
139                    _multiple = false;
140                    _name = null;
141                    _onChange = null;
142                    _onClick = null;
143                    _prefix = null;
144                    _showEmptyOption = false;
145                    _suffix = null;
146                    _title = null;
147            }
148    
149            protected String getEndPage() {
150                    return _END_PAGE;
151            }
152    
153            protected String getStartPage() {
154                    return _START_PAGE;
155            }
156    
157            protected boolean isCleanUpSetAttributes() {
158                    return _CLEAN_UP_SET_ATTRIBUTES;
159            }
160    
161            protected void setAttributes(HttpServletRequest request) {
162                    Object bean = _bean;
163    
164                    if (bean == null) {
165                            bean = pageContext.getAttribute("aui:model-context:bean");
166                    }
167    
168                    String id = _id;
169    
170                    if (Validator.isNull(id)) {
171                            id = _name;
172                    }
173    
174                    String label = _label;
175    
176                    if (label == null) {
177                            label = TextFormatter.format(_name, TextFormatter.K);
178                    }
179    
180                    String listTypeFieldName = _listTypeFieldName;
181    
182                    if (Validator.isNotNull(_listType) &&
183                            Validator.isNull(listTypeFieldName)) {
184    
185                            listTypeFieldName = "typeId";
186                    }
187    
188                    request.setAttribute("aui:select:bean", bean);
189                    request.setAttribute(
190                            "aui:select:changesContext", String.valueOf(_changesContext));
191                    request.setAttribute("aui:select:cssClass", _cssClass);
192                    request.setAttribute("aui:select:data", _data);
193                    request.setAttribute("aui:select:disabled", String.valueOf(_disabled));
194                    request.setAttribute(
195                            "aui:select:dynamicAttributes", getDynamicAttributes());
196                    request.setAttribute("aui:select:first", String.valueOf(_first));
197                    request.setAttribute("aui:select:helpMessage", _helpMessage);
198                    request.setAttribute("aui:select:id", id);
199                    request.setAttribute(
200                            "aui:select:inlineField", String.valueOf(_inlineField));
201                    request.setAttribute("aui:select:inlineLabel", _inlineLabel);
202                    request.setAttribute("aui:select:inputCssClass", _inputCssClass);
203                    request.setAttribute("aui:select:label", label);
204                    request.setAttribute("aui:select:last", String.valueOf(_last));
205                    request.setAttribute("aui:select:listType", _listType);
206                    request.setAttribute("aui:select:listTypeFieldName", listTypeFieldName);
207                    request.setAttribute("aui:select:multiple", String.valueOf(_multiple));
208                    request.setAttribute("aui:select:name", _name);
209                    request.setAttribute("aui:select:onChange", _onChange);
210                    request.setAttribute("aui:select:onClick", _onClick);
211                    request.setAttribute("aui:select:prefix", _prefix);
212                    request.setAttribute(
213                            "aui:select:showEmptyOption", String.valueOf(_showEmptyOption));
214                    request.setAttribute("aui:select:suffix", _suffix);
215                    request.setAttribute("aui:select:title", _title);
216            }
217    
218            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
219    
220            private static final String _END_PAGE = "/html/taglib/aui/select/end.jsp";
221    
222            private static final String _START_PAGE =
223                    "/html/taglib/aui/select/start.jsp";
224    
225            private Object _bean;
226            private boolean _changesContext;
227            private String _cssClass;
228            private Map<String, Object> _data;
229            private boolean _disabled;
230            private boolean _first;
231            private String _helpMessage;
232            private String _id;
233            private boolean _inlineField;
234            private String _inlineLabel;
235            private String _inputCssClass;
236            private String _label;
237            private boolean _last;
238            private String _listType;
239            private String _listTypeFieldName;
240            private boolean _multiple;
241            private String _name;
242            private String _onChange;
243            private String _onClick;
244            private String _prefix;
245            private boolean _showEmptyOption;
246            private String _suffix;
247            private String _title;
248    
249    }