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