1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.taglib.aui;
16  
17  import com.liferay.portal.kernel.util.Validator;
18  import com.liferay.taglib.util.IncludeTag;
19  
20  import javax.servlet.http.HttpServletRequest;
21  
22  /**
23   * <a href="ButtonTag.java.html"><b><i>View Source</i></b></a>
24   *
25   * @author Julio Camarero
26   * @author Jorge Ferrer
27   * @author Brian Wing Shun Chan
28   */
29  public class ButtonTag extends IncludeTag {
30  
31      public void setCssClass(String cssClass) {
32          _cssClass = cssClass;
33      }
34  
35      public void setDisabled(boolean disabled) {
36          _disabled = disabled;
37      }
38  
39      public void setName(String name) {
40          _name = name;
41      }
42  
43      public void setOnClick(String onClick) {
44          _onClick = onClick;
45      }
46  
47      public void setType(String type) {
48          _type = type;
49      }
50  
51      public void setValue(String value) {
52          _value = value;
53      }
54  
55      protected void cleanUp() {
56          _cssClass = null;
57          _disabled = false;
58          _name = null;
59          _onClick = null;
60          _type = "button";
61          _value = null;
62      }
63  
64      protected String getPage() {
65          return _PAGE;
66      }
67  
68      protected boolean isCleanUpSetAttributes() {
69          return _CLEAN_UP_SET_ATTRIBUTES;
70      }
71  
72      protected void setAttributes(HttpServletRequest request) {
73          String value = _value;
74  
75          if (Validator.isNull(value)) {
76              if (_type.equals("submit")) {
77                  value = "save";
78              }
79              else if (_type.equals("cancel")) {
80                  value = "cancel";
81              }
82              else if (_type.equals("reset")) {
83                  value = "reset";
84              }
85          }
86  
87          request.setAttribute("aui:button:cssClass", _cssClass);
88          request.setAttribute("aui:button:disabled", String.valueOf(_disabled));
89          request.setAttribute(
90              "aui:button:dynamicAttributes", getDynamicAttributes());
91          request.setAttribute("aui:button:name", _name);
92          request.setAttribute("aui:button:onClick", _onClick);
93          request.setAttribute("aui:button:type", _type);
94          request.setAttribute("aui:button:value", value);
95      }
96  
97      private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
98  
99      private static final String _PAGE = "/html/taglib/aui/button/page.jsp";
100 
101     private String _cssClass;
102     private boolean _disabled;
103     private String _name;
104     private String _onClick;
105     private String _type = "button";
106     private String _value;
107 
108 }