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    
020    import java.util.Map;
021    
022    import javax.servlet.http.HttpServletRequest;
023    
024    /**
025     * @author Julio Camarero
026     * @author Jorge Ferrer
027     * @author Brian Wing Shun Chan
028     */
029    public class ButtonTag extends IncludeTag {
030    
031            public void setCssClass(String cssClass) {
032                    _cssClass = cssClass;
033            }
034    
035            public void setData(Map<String,Object> data) {
036                    _data = data;
037            }
038    
039            public void setDisabled(boolean disabled) {
040                    _disabled = disabled;
041            }
042    
043            public void setInputCssClass(String inputCssClass) {
044                    _inputCssClass = inputCssClass;
045            }
046    
047            public void setName(String name) {
048                    _name = name;
049            }
050    
051            public void setOnClick(String onClick) {
052                    _onClick = onClick;
053            }
054    
055            public void setType(String type) {
056                    _type = type;
057            }
058    
059            public void setValue(String value) {
060                    _value = value;
061            }
062    
063            protected void cleanUp() {
064                    _cssClass = null;
065                    _data = null;
066                    _disabled = false;
067                    _inputCssClass = null;
068                    _name = null;
069                    _onClick = null;
070                    _type = "button";
071                    _value = null;
072            }
073    
074            protected String getPage() {
075                    return _PAGE;
076            }
077    
078            protected boolean isCleanUpSetAttributes() {
079                    return _CLEAN_UP_SET_ATTRIBUTES;
080            }
081    
082            protected void setAttributes(HttpServletRequest request) {
083                    String value = _value;
084    
085                    if (Validator.isNull(value)) {
086                            if (_type.equals("submit")) {
087                                    value = "save";
088                            }
089                            else if (_type.equals("cancel")) {
090                                    value = "cancel";
091                            }
092                            else if (_type.equals("reset")) {
093                                    value = "reset";
094                            }
095                    }
096    
097                    request.setAttribute("aui:button:cssClass", _cssClass);
098                    request.setAttribute("aui:button:data", _data);
099                    request.setAttribute("aui:button:disabled", String.valueOf(_disabled));
100                    request.setAttribute(
101                            "aui:button:dynamicAttributes", getDynamicAttributes());
102                    request.setAttribute("aui:button:inputCssClass", _inputCssClass);
103                    request.setAttribute("aui:button:name", _name);
104                    request.setAttribute("aui:button:onClick", _onClick);
105                    request.setAttribute("aui:button:type", _type);
106                    request.setAttribute("aui:button:value", value);
107            }
108    
109            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
110    
111            private static final String _PAGE = "/html/taglib/aui/button/page.jsp";
112    
113            private String _cssClass;
114            private Map<String, Object> _data;
115            private boolean _disabled;
116            private String _inputCssClass;
117            private String _name;
118            private String _onClick;
119            private String _type = "button";
120            private String _value;
121    
122    }