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 setAutoSize(boolean autoSize) {
030                    _autoSize = autoSize;
031            }
032    
033            public void setBean(Object bean) {
034                    _bean = bean;
035            }
036    
037            public void setCssClass(String cssClass) {
038                    _cssClass = cssClass;
039            }
040    
041            public void setDefaultLanguageId(String defaultLanguageId) {
042                    _defaultLanguageId = defaultLanguageId;
043            }
044    
045            public void setDefaultValue(Object defaultValue) {
046                    _defaultValue = defaultValue;
047            }
048    
049            public void setDisabled(boolean disabled) {
050                    _disabled = disabled;
051            }
052    
053            public void setField(String field) {
054                    _field = field;
055            }
056    
057            public void setFieldParam(String fieldParam) {
058                    _fieldParam = fieldParam;
059            }
060    
061            public void setFormat(Format format) {
062                    _format = format;
063            }
064    
065            public void setFormName(String formName) {
066                    _formName = formName;
067            }
068    
069            public void setId(String id) {
070                    _id = id;
071            }
072    
073            public void setIgnoreRequestValue(boolean ignoreRequestValue) {
074                    _ignoreRequestValue = ignoreRequestValue;
075            }
076    
077            public void setLanguageId(String languageId) {
078                    _languageId = languageId;
079            }
080    
081            public void setModel(Class<?> model) {
082                    _model = model;
083            }
084    
085            public void setPlaceholder(String placeholder) {
086                    _placeholder = placeholder;
087            }
088    
089            @Override
090            protected void cleanUp() {
091                    _autoSize = false;
092                    _bean = null;
093                    _cssClass = null;
094                    _defaultLanguageId = null;
095                    _defaultValue = null;
096                    _disabled = false;
097                    _field = null;
098                    _fieldParam = null;
099                    _format = null;
100                    _formName = "fm";
101                    _id = null;
102                    _ignoreRequestValue = false;
103                    _languageId = null;
104                    _model = null;
105                    _placeholder = null;
106            }
107    
108            @Override
109            protected String getPage() {
110                    return _PAGE;
111            }
112    
113            @Override
114            protected void setAttributes(HttpServletRequest request) {
115                    String fieldParam = _fieldParam;
116    
117                    if (Validator.isNull(fieldParam)) {
118                            fieldParam = _field;
119                    }
120    
121                    String id = _id;
122    
123                    if (Validator.isNull(id)) {
124                            id = fieldParam;
125                    }
126    
127                    request.setAttribute(
128                            "liferay-ui:input-field:autoSize", String.valueOf(_autoSize));
129                    request.setAttribute("liferay-ui:input-field:bean", _bean);
130                    request.setAttribute("liferay-ui:input-field:cssClass", _cssClass);
131                    request.setAttribute(
132                            "liferay-ui:input-field:defaultLanguageId", _defaultLanguageId);
133                    request.setAttribute(
134                            "liferay-ui:input-field:defaultValue", _defaultValue);
135                    request.setAttribute(
136                            "liferay-ui:input-field:disabled", String.valueOf(_disabled));
137                    request.setAttribute("liferay-ui:input-field:field", _field);
138                    request.setAttribute("liferay-ui:input-field:fieldParam", fieldParam);
139                    request.setAttribute("liferay-ui:input-field:id", id);
140                    request.setAttribute("liferay-ui:input-field:format", _format);
141                    request.setAttribute("liferay-ui:input-field:formName", _formName);
142                    request.setAttribute(
143                            "liferay-ui:input-field:ignoreRequestValue",
144                            String.valueOf(_ignoreRequestValue));
145                    request.setAttribute("liferay-ui:input-field:languageId", _languageId);
146                    request.setAttribute("liferay-ui:input-field:model", _model.getName());
147                    request.setAttribute(
148                            "liferay-ui:input-field:placeholder", _placeholder);
149            }
150    
151            private static final String _PAGE = "/html/taglib/ui/input_field/page.jsp";
152    
153            private boolean _autoSize;
154            private Object _bean;
155            private String _cssClass;
156            private String _defaultLanguageId;
157            private Object _defaultValue;
158            private boolean _disabled;
159            private String _field;
160            private String _fieldParam;
161            private Format _format;
162            private String _formName = "fm";
163            private String _id;
164            private boolean _ignoreRequestValue;
165            private String _languageId;
166            private Class<?> _model;
167            private String _placeholder;
168    
169    }