001
014
015 package com.liferay.taglib.ui;
016
017 import com.liferay.portal.kernel.dao.search.DisplayTerms;
018 import com.liferay.portal.kernel.dao.search.RowChecker;
019 import com.liferay.portal.kernel.dao.search.SearchContainer;
020 import com.liferay.portal.kernel.util.JavaConstants;
021 import com.liferay.portal.kernel.util.ListUtil;
022 import com.liferay.portal.kernel.util.OrderByComparator;
023 import com.liferay.portal.kernel.util.SearchContainerReference;
024 import com.liferay.portal.kernel.util.StringUtil;
025 import com.liferay.portal.kernel.util.Validator;
026 import com.liferay.taglib.util.ParamAndPropertyAncestorTagImpl;
027
028 import java.util.List;
029
030 import javax.portlet.MimeResponse;
031 import javax.portlet.PortletRequest;
032 import javax.portlet.PortletResponse;
033 import javax.portlet.PortletURL;
034
035 import javax.servlet.jsp.JspException;
036
037
041 public class SearchContainerTag<R> extends ParamAndPropertyAncestorTagImpl {
042
043 @Override
044 public int doEndTag() {
045 pageContext.setAttribute(
046 _searchContainer.getTotalVar(), _searchContainer.getTotal());
047
048 _curParam = SearchContainer.DEFAULT_CUR_PARAM;
049 _delta = SearchContainer.DEFAULT_DELTA;
050 _deltaConfigurable = SearchContainer.DEFAULT_DELTA_CONFIGURABLE;
051 _deltaParam = SearchContainer.DEFAULT_DELTA_PARAM;
052 _displayTerms = null;
053 _emptyResultsMessage = null;
054 _headerNames = null;
055 _hover = false;
056 _id = null;
057 _iteratorURL = null;
058 _orderByCol = null;
059 _orderByColParam = SearchContainer.DEFAULT_ORDER_BY_COL_PARAM;
060 _orderByComparator = null;
061 _orderByType = null;
062 _orderByTypeParam = SearchContainer.DEFAULT_ORDER_BY_TYPE_PARAM;
063 _rowChecker = null;
064 _searchContainer = null;
065 _searchTerms = null;
066 _total = 0;
067 _totalVar = SearchContainer.DEFAULT_TOTAL_VAR;
068 _var = SearchContainer.DEFAULT_VAR;
069
070 return EVAL_PAGE;
071 }
072
073 @Override
074 public int doStartTag() throws JspException {
075 try {
076 PortletRequest portletRequest =
077 (PortletRequest)request.getAttribute(
078 JavaConstants.JAVAX_PORTLET_REQUEST);
079 PortletResponse portletResponse =
080 (PortletResponse)request.getAttribute(
081 JavaConstants.JAVAX_PORTLET_RESPONSE);
082
083 if (_iteratorURL == null) {
084 _iteratorURL =
085 ((MimeResponse)portletResponse).createRenderURL();
086 }
087
088 if (_searchContainer == null) {
089 _searchContainer = new SearchContainer<R>(
090 portletRequest, _displayTerms, _searchTerms, getCurParam(),
091 getDelta(), _iteratorURL, null, _emptyResultsMessage);
092 }
093
094 _searchContainer.setDeltaConfigurable(_deltaConfigurable);
095
096 if (Validator.isNotNull(_emptyResultsMessage)) {
097 _searchContainer.setEmptyResultsMessage(_emptyResultsMessage);
098 }
099
100 if (_headerNames != null) {
101 _searchContainer.setHeaderNames(_headerNames);
102 }
103
104 _searchContainer.setHover(_hover);
105 _searchContainer.setId(_id);
106
107 if (Validator.isNotNull(_orderByCol)) {
108 _searchContainer.setOrderByCol(_orderByCol);
109 }
110
111 if (Validator.isNotNull(_orderByColParam)) {
112 _searchContainer.setOrderByColParam(_orderByColParam);
113 }
114
115 if (_orderByComparator != null) {
116 _searchContainer.setOrderByComparator(_orderByComparator);
117 }
118
119 if (Validator.isNotNull(_orderByType)) {
120 _searchContainer.setOrderByType(_orderByType);
121 }
122
123 if (Validator.isNotNull(_orderByTypeParam)) {
124 _searchContainer.setOrderByTypeParam(_orderByTypeParam);
125 }
126
127 if (_rowChecker != null) {
128 _searchContainer.setRowChecker(_rowChecker);
129 }
130
131 if (_total != 0) {
132 _searchContainer.setTotal(_total);
133 }
134
135 if (Validator.isNotNull(_totalVar)) {
136 _searchContainer.setTotalVar(_totalVar);
137 }
138
139 pageContext.setAttribute(
140 _searchContainer.getTotalVar(), _searchContainer.getTotal());
141 pageContext.setAttribute(_var, _searchContainer);
142
143 SearchContainerReference searchContainerReference =
144 (SearchContainerReference)pageContext.getAttribute(
145 "searchContainerReference");
146
147 if ((searchContainerReference != null) &&
148 !_var.equals(SearchContainer.DEFAULT_VAR)) {
149
150 searchContainerReference.register(_var, _searchContainer);
151 }
152
153 return EVAL_BODY_INCLUDE;
154 }
155 catch (Exception e) {
156 throw new JspException(e);
157 }
158 }
159
160 public String getCurParam() {
161 return _curParam;
162 }
163
164 public int getDelta() {
165 return _delta;
166 }
167
168 public String getDeltaParam() {
169 return _deltaParam;
170 }
171
172 public DisplayTerms getDisplayTerms() {
173 return _displayTerms;
174 }
175
176 public String getEmptyResultsMessage() {
177 return _emptyResultsMessage;
178 }
179
180 public PortletURL getIteratorURL() {
181 return _iteratorURL;
182 }
183
184 public String getOrderByCol() {
185 return _orderByCol;
186 }
187
188 public String getOrderByColParam() {
189 return _orderByColParam;
190 }
191
192 public OrderByComparator<R> getOrderByComparator() {
193 return _orderByComparator;
194 }
195
196 public String getOrderByType() {
197 return _orderByType;
198 }
199
200 public String getOrderByTypeParam() {
201 return _orderByTypeParam;
202 }
203
204 public RowChecker getRowChecker() {
205 return _rowChecker;
206 }
207
208 public SearchContainer<R> getSearchContainer() {
209 return _searchContainer;
210 }
211
212 public DisplayTerms getSearchTerms() {
213 return _searchTerms;
214 }
215
216 public int getTotal() {
217 return _total;
218 }
219
220 public String getTotalVar() {
221 return _totalVar;
222 }
223
224 public String getVar() {
225 return _var;
226 }
227
228 public boolean isDeltaConfigurable() {
229 return _deltaConfigurable;
230 }
231
232
235 @Deprecated
236 public boolean isHasResults() {
237 return true;
238 }
239
240 public boolean isHover() {
241 return _hover;
242 }
243
244 public void setCurParam(String curParam) {
245 _curParam = curParam;
246 }
247
248 public void setDelta(int delta) {
249 _delta = delta;
250 }
251
252 public void setDeltaConfigurable(boolean deltaConfigurable) {
253 _deltaConfigurable = deltaConfigurable;
254 }
255
256 public void setDeltaParam(String deltaParam) {
257 _deltaParam = deltaParam;
258 }
259
260 public void setDisplayTerms(DisplayTerms displayTerms) {
261 _displayTerms = displayTerms;
262 }
263
264 public void setEmptyResultsMessage(String emptyResultsMessage) {
265 _emptyResultsMessage = emptyResultsMessage;
266 }
267
268
271 @Deprecated
272 public void setHasResults(boolean hasResults) {
273 }
274
275 public void setHeaderNames(String headerNames) {
276 _headerNames = ListUtil.toList(StringUtil.split(headerNames));
277 }
278
279 public void setHover(boolean hover) {
280 _hover = hover;
281 }
282
283 public void setId(String id) {
284 _id = id;
285 }
286
287 public void setIteratorURL(PortletURL iteratorURL) {
288 _iteratorURL = iteratorURL;
289 }
290
291 public void setOrderByCol(String orderByCol) {
292 _orderByCol = orderByCol;
293 }
294
295 public void setOrderByColParam(String orderByColParam) {
296 _orderByColParam = orderByColParam;
297 }
298
299 public void setOrderByComparator(OrderByComparator<R> orderByComparator) {
300 _orderByComparator = orderByComparator;
301 }
302
303 public void setOrderByType(String orderByType) {
304 _orderByType = orderByType;
305 }
306
307 public void setOrderByTypeParam(String orderByTypeParam) {
308 _orderByTypeParam = orderByTypeParam;
309 }
310
311 public void setRowChecker(RowChecker rowChecker) {
312 _rowChecker = rowChecker;
313 }
314
315 public void setSearchContainer(SearchContainer<R> searchContainer) {
316 _searchContainer = searchContainer;
317 }
318
319 public void setSearchTerms(DisplayTerms searchTerms) {
320 _searchTerms = searchTerms;
321 }
322
323 public void setTotal(int total) {
324 _total = total;
325 }
326
327 public void setTotalVar(String totalVar) {
328 _totalVar = totalVar;
329 }
330
331 public void setVar(String var) {
332 _var = var;
333 }
334
335 private String _curParam = SearchContainer.DEFAULT_CUR_PARAM;
336 private int _delta = SearchContainer.DEFAULT_DELTA;
337 private boolean _deltaConfigurable =
338 SearchContainer.DEFAULT_DELTA_CONFIGURABLE;
339 private String _deltaParam = SearchContainer.DEFAULT_DELTA_PARAM;
340 private DisplayTerms _displayTerms;
341 private String _emptyResultsMessage;
342 private List<String> _headerNames;
343 private boolean _hover = true;
344 private String _id;
345 private PortletURL _iteratorURL;
346 private String _orderByCol;
347 private String _orderByColParam =
348 SearchContainer.DEFAULT_ORDER_BY_COL_PARAM;
349 private OrderByComparator<R> _orderByComparator;
350 private String _orderByType;
351 private String _orderByTypeParam =
352 SearchContainer.DEFAULT_ORDER_BY_TYPE_PARAM;
353 private RowChecker _rowChecker;
354 private SearchContainer<R> _searchContainer;
355 private DisplayTerms _searchTerms;
356 private int _total;
357 private String _totalVar = SearchContainer.DEFAULT_TOTAL_VAR;
358 private String _var = SearchContainer.DEFAULT_VAR;
359
360 }