001
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.JspWriter;
023 import javax.servlet.jsp.PageContext;
024 import javax.servlet.jsp.tagext.TagSupport;
025
026
029 public class ToggleValueTag extends TagSupport {
030
031
034 @Deprecated
035 public static void doTag(
036 String id, PageContext pageContext, HttpServletRequest request)
037 throws Exception {
038
039 doTag(id, "block", pageContext);
040 }
041
042 public static void doTag(
043 String id, String defaultValue, PageContext pageContext)
044 throws Exception {
045
046 HttpServletRequest request =
047 (HttpServletRequest)pageContext.getRequest();
048
049 String value = SessionClicks.get(request, id, StringPool.BLANK);
050
051 if (value.equals(StringPool.BLANK)) {
052 value = defaultValue;
053 }
054
055 JspWriter jspWriter = pageContext.getOut();
056
057 jspWriter.write(value);
058 }
059
060 @Override
061 public int doEndTag() throws JspException {
062 try {
063 doTag(_id, _defaultValue, pageContext);
064
065 return EVAL_PAGE;
066 }
067 catch (Exception e) {
068 throw new JspException(e);
069 }
070 }
071
072 public void setDefaultValue(String defaultValue) {
073 _defaultValue = defaultValue;
074 }
075
076 @Override
077 public void setId(String id) {
078 _id = id;
079 }
080
081 private String _defaultValue = "block";
082 private String _id;
083
084 }