001    /**
002     * Copyright (c) 2000-2013 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.ui;
016    
017    import com.liferay.portal.kernel.util.Validator;
018    import com.liferay.taglib.util.IncludeTag;
019    
020    import java.text.Format;
021    
022    import javax.servlet.http.HttpServletRequest;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class InputFieldTag extends IncludeTag {
028    
029            public void setAutoFocus(boolean autoFocus) {
030                    _autoFocus = autoFocus;
031            }
032    
033            public void setAutoSize(boolean autoSize) {
034                    _autoSize = autoSize;
035            }
036    
037            public void setBean(Object bean) {
038                    _bean = bean;
039            }
040    
041            public void setCssClass(String cssClass) {
042                    _cssClass = cssClass;
043            }
044    
045            public void setDateTogglerCheckboxLabel(String dateTogglerCheckboxLabel) {
046                    _dateTogglerCheckboxLabel = dateTogglerCheckboxLabel;
047            }
048    
049            public void setDefaultLanguageId(String defaultLanguageId) {
050                    _defaultLanguageId = defaultLanguageId;
051            }
052    
053            public void setDefaultValue(Object defaultValue) {
054                    _defaultValue = defaultValue;
055            }
056    
057            public void setDisabled(boolean disabled) {
058                    _disabled = disabled;
059            }
060    
061            public void setField(String field) {
062                    _field = field;
063            }
064    
065            public void setFieldParam(String fieldParam) {
066                    _fieldParam = fieldParam;
067            }
068    
069            public void setFormat(Format format) {
070                    _format = format;
071            }
072    
073            public void setFormName(String formName) {
074                    _formName = formName;
075            }
076    
077            public void setId(String id) {
078                    _id = id;
079            }
080    
081            public void setIgnoreRequestValue(boolean ignoreRequestValue) {
082                    _ignoreRequestValue = ignoreRequestValue;
083            }
084    
085            public void setLanguageId(String languageId) {
086                    _languageId = languageId;
087            }
088    
089            public void setModel(Class<?> model) {
090                    _model = model;
091            }
092    
093            public void setPlaceholder(String placeholder) {
094                    _placeholder = placeholder;
095            }
096    
097            @Override
098            protected void cleanUp() {
099                    _autoFocus = false;
100                    _autoSize = false;
101                    _bean = null;
102                    _cssClass = null;
103                    _dateTogglerCheckboxLabel = null;
104                    _defaultLanguageId = null;
105                    _defaultValue = null;
106                    _disabled = false;
107                    _field = null;
108                    _fieldParam = null;
109                    _format = null;
110                    _formName = "fm";
111                    _id = null;
112                    _ignoreRequestValue = false;
113                    _languageId = null;
114                    _model = null;
115                    _placeholder = null;
116            }
117    
118            @Override
119            protected String getPage() {
120                    return _PAGE;
121            }
122    
123            @Override
124            protected void setAttributes(HttpServletRequest request) {
125                    String fieldParam = _fieldParam;
126    
127                    if (Validator.isNull(fieldParam)) {
128                            fieldParam = _field;
129                    }
130    
131                    String id = _id;
132    
133                    if (Validator.isNull(id)) {
134                            id = fieldParam;
135                    }
136    
137                    request.setAttribute(
138                            "liferay-ui:input-field:autoFocus", String.valueOf(_autoFocus));
139                    request.setAttribute(
140                            "liferay-ui:input-field:autoSize", String.valueOf(_autoSize));
141                    request.setAttribute("liferay-ui:input-field:bean", _bean);
142                    request.setAttribute("liferay-ui:input-field:cssClass", _cssClass);
143                    request.setAttribute(
144                            "liferay-ui:input-field:dateTogglerCheckboxLabel",
145                            _dateTogglerCheckboxLabel);
146                    request.setAttribute(
147                            "liferay-ui:input-field:defaultLanguageId", _defaultLanguageId);
148                    request.setAttribute(
149                            "liferay-ui:input-field:defaultValue", _defaultValue);
150                    request.setAttribute(
151                            "liferay-ui:input-field:disabled", String.valueOf(_disabled));
152                    request.setAttribute("liferay-ui:input-field:field", _field);
153                    request.setAttribute("liferay-ui:input-field:fieldParam", fieldParam);
154                    request.setAttribute("liferay-ui:input-field:id", id);
155                    request.setAttribute("liferay-ui:input-field:format", _format);
156                    request.setAttribute("liferay-ui:input-field:formName", _formName);
157                    request.setAttribute(
158                            "liferay-ui:input-field:ignoreRequestValue",
159                            String.valueOf(_ignoreRequestValue));
160                    request.setAttribute("liferay-ui:input-field:languageId", _languageId);
161                    request.setAttribute("liferay-ui:input-field:model", _model.getName());
162                    request.setAttribute(
163                            "liferay-ui:input-field:placeholder", _placeholder);
164            }
165    
166            private static final String _PAGE = "/html/taglib/ui/input_field/page.jsp";
167    
168            private boolean _autoFocus;
169            private boolean _autoSize;
170            private Object _bean;
171            private String _cssClass;
172            private String _dateTogglerCheckboxLabel;
173            private String _defaultLanguageId;
174            private Object _defaultValue;
175            private boolean _disabled;
176            private String _field;
177            private String _fieldParam;
178            private Format _format;
179            private String _formName = "fm";
180            private String _id;
181            private boolean _ignoreRequestValue;
182            private String _languageId;
183            private Class<?> _model;
184            private String _placeholder;
185    
186    }