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.taglib.util.IncludeTag;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.jsp.tagext.DynamicAttributes;
24  
25  /**
26   * <a href="ButtonTag.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Julio Camarero
29   * @author Jorge Ferrer
30   * @author Brian Wing Shun Chan
31   */
32  public class ButtonTag extends IncludeTag implements DynamicAttributes {
33  
34      public int doStartTag() {
35          HttpServletRequest request =
36              (HttpServletRequest)pageContext.getRequest();
37  
38          if (_value == null) {
39              if (_type.equals("submit")) {
40                  _value = "save";
41              }
42              else if (_type.equals("cancel")) {
43                  _value = "cancel";
44              }
45              else if (_type.equals("reset")) {
46                  _value = "reset";
47              }
48          }
49  
50          request.setAttribute("aui:button:cssClass", _cssClass);
51          request.setAttribute("aui:button:disabled", String.valueOf(_disabled));
52          request.setAttribute(
53              "aui:button:dynamicAttributes", _dynamicAttributes);
54          request.setAttribute("aui:button:name", _name);
55          request.setAttribute("aui:button:onClick", _onClick);
56          request.setAttribute("aui:button:type", _type);
57          request.setAttribute("aui:button:value", _value);
58  
59          return EVAL_BODY_BUFFERED;
60      }
61  
62      public void setCssClass(String cssClass) {
63          _cssClass = cssClass;
64      }
65  
66      public void setDisabled(boolean disabled) {
67          _disabled = disabled;
68      }
69  
70      public void setDynamicAttribute(
71          String uri, String localName, Object value) {
72  
73          _dynamicAttributes.put(localName, value);
74      }
75  
76      public void setName(String name) {
77          _name = name;
78      }
79  
80      public void setOnClick(String onClick) {
81          _onClick = onClick;
82      }
83  
84      public void setType(String type) {
85          _type = type;
86      }
87  
88      public void setValue(String value) {
89          _value = value;
90      }
91  
92      protected String getDefaultPage() {
93          return _PAGE;
94      }
95  
96      private static final String _PAGE = "/html/taglib/aui/button/page.jsp";
97  
98      private String _cssClass;
99      private boolean _disabled;
100     private Map<String, Object> _dynamicAttributes =
101         new HashMap<String, Object>();
102     private String _name;
103     private String _onClick;
104     private String _type = "button";
105     private String _value;
106 
107 }