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.ui;
016    
017    import com.liferay.portal.kernel.util.StringPool;
018    import com.liferay.portal.util.SessionClicks;
019    
020    import javax.servlet.http.HttpServletRequest;
021    import javax.servlet.jsp.JspException;
022    import javax.servlet.jsp.PageContext;
023    import javax.servlet.jsp.tagext.TagSupport;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class ToggleValueTag extends TagSupport {
029    
030            public static void doTag(String id, PageContext pageContext)
031                    throws Exception {
032    
033                    HttpServletRequest request =
034                            (HttpServletRequest)pageContext.getRequest();
035    
036                    String value = SessionClicks.get(request, id, StringPool.BLANK);
037    
038                    if (value.equals(StringPool.BLANK)) {
039                            value = "block";
040                    }
041    
042                    pageContext.getOut().print(value);
043            }
044    
045            /**
046             * @deprecated
047             */
048            public static void doTag(
049                            String id, PageContext pageContext, HttpServletRequest request)
050                    throws Exception {
051    
052                    doTag(id, pageContext);
053            }
054    
055            public int doEndTag() throws JspException {
056                    try {
057                            doTag(_id, pageContext);
058    
059                            return EVAL_PAGE;
060                    }
061                    catch (Exception e) {
062                            throw new JspException(e);
063                    }
064            }
065    
066            public void setId(String id) {
067                    _id = id;
068            }
069    
070            private String _id;
071    
072    }