001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.taglib.aui;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.kernel.util.Validator;
019    import com.liferay.taglib.aui.base.BaseOptionTag;
020    
021    import javax.servlet.http.HttpServletRequest;
022    import javax.servlet.jsp.JspWriter;
023    
024    /**
025     * @author Julio Camarero
026     * @author Jorge Ferrer
027     * @author Brian Wing Shun Chan
028     */
029    public class OptionTag extends BaseOptionTag {
030    
031            @Override
032            protected boolean isCleanUpSetAttributes() {
033                    return _CLEAN_UP_SET_ATTRIBUTES;
034            }
035    
036            @Override
037            protected int processEndTag() throws Exception {
038                    JspWriter jspWriter = pageContext.getOut();
039    
040                    jspWriter.write("</option>");
041    
042                    return EVAL_PAGE;
043            }
044    
045            @Override
046            protected void setAttributes(HttpServletRequest request) {
047                    super.setAttributes(request);
048    
049                    Object value = getValue();
050    
051                    if (value == null) {
052                            value = getLabel();
053                    }
054    
055                    boolean selected = getSelected();
056    
057                    String selectValue = GetterUtil.getString(
058                            (String)request.getAttribute("aui:select:value"));
059    
060                    if (Validator.isNotNull(selectValue)) {
061                            selected = selectValue.equals(String.valueOf(value));
062                    }
063    
064                    setNamespacedAttribute(request, "selected", String.valueOf(selected));
065                    setNamespacedAttribute(request, "value", value);
066            }
067    
068            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
069    
070    }