001    /**
002     * Copyright (c) 2000-present 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.taglib.util.IncludeTag;
018    
019    import java.util.List;
020    
021    import javax.servlet.http.HttpServletRequest;
022    import javax.servlet.jsp.JspException;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class InputCheckBoxTag extends IncludeTag {
028    
029            @Override
030            public int doEndTag() throws JspException {
031                    updateFormCheckboxNames();
032    
033                    return super.doEndTag();
034            }
035    
036            public void setCssClass(String cssClass) {
037                    _cssClass = cssClass;
038            }
039    
040            public void setDefaultValue(boolean defaultValue) {
041                    _defaultValue = Boolean.valueOf(defaultValue);
042            }
043    
044            public void setDisabled(boolean disabled) {
045                    _disabled = disabled;
046            }
047    
048            public void setFormName(String formName) {
049                    _formName = formName;
050            }
051    
052            public void setId(String id) {
053                    _id = id;
054            }
055    
056            public void setOnClick(String onClick) {
057                    _onClick = onClick;
058            }
059    
060            public void setParam(String param) {
061                    _param = param;
062            }
063    
064            @Override
065            protected void cleanUp() {
066                    _cssClass = null;
067                    _defaultValue = Boolean.FALSE;
068                    _disabled = false;
069                    _formName = "fm";
070                    _id = null;
071                    _onClick = null;
072                    _param = null;
073            }
074    
075            @Override
076            protected String getPage() {
077                    return _PAGE;
078            }
079    
080            @Override
081            protected void setAttributes(HttpServletRequest request) {
082                    request.setAttribute("liferay-ui:input-checkbox:cssClass", _cssClass);
083                    request.setAttribute(
084                            "liferay-ui:input-checkbox:defaultValue", _defaultValue);
085                    request.setAttribute(
086                            "liferay-ui:input-checkbox:disabled", String.valueOf(_disabled));
087                    request.setAttribute("liferay-ui:input-checkbox:formName", _formName);
088                    request.setAttribute("liferay-ui:input-checkbox:id", _id);
089                    request.setAttribute("liferay-ui:input-checkbox:onClick", _onClick);
090                    request.setAttribute("liferay-ui:input-checkbox:param", _param);
091            }
092    
093            protected void updateFormCheckboxNames() {
094                    List<String> checkboxNames = (List<String>)request.getAttribute(
095                            "aui:form:checkboxNames");
096    
097                    if (checkboxNames != null) {
098                            checkboxNames.add(_param);
099                    }
100            }
101    
102            private static final String _PAGE =
103                    "/html/taglib/ui/input_checkbox/page.jsp";
104    
105            private String _cssClass;
106            private Boolean _defaultValue = Boolean.FALSE;
107            private boolean _disabled;
108            private String _formName = "fm";
109            private String _id;
110            private String _onClick;
111            private String _param;
112    
113    }