001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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 setLabel(String label) {
073                    _label = label;
074            }
075    
076            public void setLast(boolean last) {
077                    _last = last;
078            }
079    
080            public void setListType(String listType) {
081                    _listType = listType;
082            }
083    
084            public void setListTypeFieldName(String listTypeFieldName) {
085                    _listTypeFieldName = listTypeFieldName;
086            }
087    
088            public void setMultiple(boolean multiple) {
089                    _multiple = multiple;
090            }
091    
092            public void setName(String name) {
093                    _name = name;
094            }
095    
096            public void setPrefix(String prefix) {
097                    _prefix = prefix;
098            }
099    
100            public void setShowEmptyOption(boolean showEmptyOption) {
101                    _showEmptyOption = showEmptyOption;
102            }
103    
104            public void setTitle(String title) {
105                    _title = title;
106            }
107    
108            public void setSuffix(String suffix) {
109                    _suffix = suffix;
110            }
111    
112            protected void cleanUp() {
113                    _bean = null;
114                    _changesContext = false;
115                    _cssClass = null;
116                    _data = null;
117                    _first = false;
118                    _helpMessage = null;
119                    _inlineField = false;
120                    _inlineLabel = null;
121                    _id = null;
122                    _label = null;
123                    _last = false;
124                    _listType = null;
125                    _listTypeFieldName = null;
126                    _multiple = false;
127                    _name = null;
128                    _prefix = null;
129                    _showEmptyOption = false;
130                    _suffix = null;
131                    _title = null;
132            }
133    
134            protected String getEndPage() {
135                    return _END_PAGE;
136            }
137    
138            protected String getStartPage() {
139                    return _START_PAGE;
140            }
141    
142            protected boolean isCleanUpSetAttributes() {
143                    return _CLEAN_UP_SET_ATTRIBUTES;
144            }
145    
146            protected void setAttributes(HttpServletRequest request) {
147                    Object bean = _bean;
148    
149                    if (bean == null) {
150                            bean = pageContext.getAttribute("aui:model-context:bean");
151                    }
152    
153                    String id = _id;
154    
155                    if (Validator.isNull(id)) {
156                            id = _name;
157                    }
158    
159                    String label = _label;
160    
161                    if (label == null) {
162                            label = TextFormatter.format(_name, TextFormatter.K);
163                    }
164    
165                    String listTypeFieldName = _listTypeFieldName;
166    
167                    if (Validator.isNotNull(_listType) &&
168                            Validator.isNull(listTypeFieldName)) {
169    
170                            listTypeFieldName = "typeId";
171                    }
172    
173                    request.setAttribute("aui:select:bean", bean);
174                    request.setAttribute(
175                            "aui:select:changesContext", String.valueOf(_changesContext));
176                    request.setAttribute("aui:select:cssClass", _cssClass);
177                    request.setAttribute("aui:select:data", _data);
178                    request.setAttribute("aui:select:disabled", String.valueOf(_disabled));
179                    request.setAttribute(
180                            "aui:select:dynamicAttributes", getDynamicAttributes());
181                    request.setAttribute("aui:select:first", String.valueOf(_first));
182                    request.setAttribute("aui:select:helpMessage", _helpMessage);
183                    request.setAttribute(
184                            "aui:select:inlineField", String.valueOf(_inlineField));
185                    request.setAttribute("aui:select:inlineLabel", _inlineLabel);
186                    request.setAttribute("aui:select:id", id);
187                    request.setAttribute("aui:select:label", label);
188                    request.setAttribute("aui:select:last", String.valueOf(_last));
189                    request.setAttribute("aui:select:listType", _listType);
190                    request.setAttribute("aui:select:listTypeFieldName", listTypeFieldName);
191                    request.setAttribute("aui:select:multiple", String.valueOf(_multiple));
192                    request.setAttribute("aui:select:name", _name);
193                    request.setAttribute("aui:select:prefix", _prefix);
194                    request.setAttribute(
195                            "aui:select:showEmptyOption", String.valueOf(_showEmptyOption));
196                    request.setAttribute("aui:select:suffix", _suffix);
197                    request.setAttribute("aui:select:title", _title);
198            }
199    
200            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
201    
202            private static final String _END_PAGE = "/html/taglib/aui/select/end.jsp";
203    
204            private static final String _START_PAGE =
205                    "/html/taglib/aui/select/start.jsp";
206    
207            private Object _bean;
208            private boolean _changesContext;
209            private String _cssClass;
210            private Map<String, Object> _data;
211            private boolean _disabled;
212            private boolean _first;
213            private String _helpMessage;
214            private String _id;
215            private boolean _inlineField;
216            private String _inlineLabel;
217            private String _label;
218            private boolean _last;
219            private String _listType;
220            private String _listTypeFieldName;
221            private boolean _multiple;
222            private String _name;
223            private String _prefix;
224            private boolean _showEmptyOption;
225            private String _suffix;
226            private String _title;
227    
228    }