1
22
23 package com.liferay.taglib.ui;
24
25 import com.liferay.portal.kernel.util.JavaConstants;
26 import com.liferay.portal.kernel.util.StringPool;
27 import com.liferay.portal.kernel.util.Validator;
28 import com.liferay.taglib.util.ParamAndPropertyAncestorTagImpl;
29
30 import javax.portlet.RenderResponse;
31
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.jsp.JspException;
34
35
40 public class SectionTag extends ParamAndPropertyAncestorTagImpl {
41
42 public int doStartTag() throws JspException {
43 _tabsTag = (TabsTag)findAncestorWithClass(this, TabsTag.class);
44
45 if (_tabsTag == null) {
46 throw new JspException();
47 }
48
49 try {
50 HttpServletRequest request =
51 (HttpServletRequest)pageContext.getRequest();
52
53 RenderResponse renderResponse =
54 (RenderResponse)request.getAttribute(
55 JavaConstants.JAVAX_PORTLET_RESPONSE);
56
57 String namespace = StringPool.BLANK;
58
59 if (renderResponse != null) {
60 namespace = renderResponse.getNamespace();
61 }
62
63 String sectionParam = _tabsTag.getParam();
64 String sectionName = _tabsTag.getSectionName();
65 _sectionSelected = Boolean.valueOf(_tabsTag.getSectionSelected());
66 String sectionScroll = namespace + sectionParam + "TabsScroll";
67 String sectionRedirectParams =
68 "&scroll=" + sectionScroll + "&" + sectionParam + "=" +
69 sectionName;
70
71 _tabsTag.incrementSection();
72
73 request.setAttribute("liferay-ui:section:param", sectionParam);
74 request.setAttribute("liferay-ui:section:name", sectionName);
75 request.setAttribute(
76 "liferay-ui:section:selected", _sectionSelected);
77 request.setAttribute("liferay-ui:section:scroll", sectionScroll);
78
79 pageContext.setAttribute("sectionSelected", _sectionSelected);
80 pageContext.setAttribute("sectionParam", sectionParam);
81 pageContext.setAttribute("sectionName", sectionName);
82 pageContext.setAttribute("sectionScroll", sectionScroll);
83 pageContext.setAttribute(
84 "sectionRedirectParams", sectionRedirectParams);
85
86 if (!_tabsTag.isRefresh() || _sectionSelected.booleanValue()) {
87 if (!_tabsTag.isRefresh()) {
88 include(getStartPage());
89 }
90
91 return EVAL_BODY_INCLUDE;
92 }
93 else {
94 return EVAL_PAGE;
95 }
96 }
97 catch (Exception e) {
98 throw new JspException(e);
99 }
100 }
101
102 public int doEndTag() throws JspException {
103 try {
104 if (!_tabsTag.isRefresh() || _sectionSelected.booleanValue()) {
105 if (!_tabsTag.isRefresh()) {
106 include(getEndPage());
107 }
108
109 return EVAL_BODY_INCLUDE;
110 }
111 else {
112 return EVAL_PAGE;
113 }
114 }
115 catch (Exception e) {
116 throw new JspException(e);
117 }
118 }
119
120 public String getStartPage() {
121 if (Validator.isNull(_startPage)) {
122 return _START_PAGE;
123 }
124 else {
125 return _startPage;
126 }
127 }
128
129 public void setStartPage(String startPage) {
130 _startPage = startPage;
131 }
132
133 public String getEndPage() {
134 if (Validator.isNull(_endPage)) {
135 return _END_PAGE;
136 }
137 else {
138 return _endPage;
139 }
140 }
141
142 public void setEndPage(String endPage) {
143 _endPage = endPage;
144 }
145
146 private static final String _START_PAGE =
147 "/html/taglib/ui/section/start.jsp";
148
149 private static final String _END_PAGE = "/html/taglib/ui/section/end.jsp";
150
151 private String _startPage;
152 private String _endPage;
153 private TabsTag _tabsTag = null;
154 private Boolean _sectionSelected = Boolean.FALSE;
155
156 }