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 setName(String name) {
044                    _name = name;
045            }
046    
047            public void setOnClick(String onClick) {
048                    _onClick = onClick;
049            }
050    
051            public void setType(String type) {
052                    _type = type;
053            }
054    
055            public void setValue(String value) {
056                    _value = value;
057            }
058    
059            protected void cleanUp() {
060                    _cssClass = null;
061                    _data = null;
062                    _disabled = false;
063                    _name = null;
064                    _onClick = null;
065                    _type = "button";
066                    _value = null;
067            }
068    
069            protected String getPage() {
070                    return _PAGE;
071            }
072    
073            protected boolean isCleanUpSetAttributes() {
074                    return _CLEAN_UP_SET_ATTRIBUTES;
075            }
076    
077            protected void setAttributes(HttpServletRequest request) {
078                    String value = _value;
079    
080                    if (Validator.isNull(value)) {
081                            if (_type.equals("submit")) {
082                                    value = "save";
083                            }
084                            else if (_type.equals("cancel")) {
085                                    value = "cancel";
086                            }
087                            else if (_type.equals("reset")) {
088                                    value = "reset";
089                            }
090                    }
091    
092                    request.setAttribute("aui:button:cssClass", _cssClass);
093                    request.setAttribute("aui:button:data", _data);
094                    request.setAttribute("aui:button:disabled", String.valueOf(_disabled));
095                    request.setAttribute(
096                            "aui:button:dynamicAttributes", getDynamicAttributes());
097                    request.setAttribute("aui:button:name", _name);
098                    request.setAttribute("aui:button:onClick", _onClick);
099                    request.setAttribute("aui:button:type", _type);
100                    request.setAttribute("aui:button:value", value);
101            }
102    
103            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
104    
105            private static final String _PAGE = "/html/taglib/aui/button/page.jsp";
106    
107            private String _cssClass;
108            private Map<String, Object> _data;
109            private boolean _disabled;
110            private String _name;
111            private String _onClick;
112            private String _type = "button";
113            private String _value;
114    
115    }