001
014
015 package com.liferay.taglib.ui;
016
017 import com.liferay.portal.kernel.dao.search.ResultRow;
018 import com.liferay.portal.kernel.dao.search.SearchEntry;
019 import com.liferay.portal.kernel.language.LanguageUtil;
020 import com.liferay.portal.kernel.util.ServerDetector;
021 import com.liferay.portal.kernel.util.StringPool;
022 import com.liferay.taglib.search.ButtonSearchEntry;
023
024 import java.util.List;
025
026 import javax.portlet.PortletURL;
027
028 import javax.servlet.jsp.JspException;
029 import javax.servlet.jsp.JspTagException;
030
031
034 public class SearchContainerColumnButtonTag<R>
035 extends SearchContainerColumnTag {
036
037 @Override
038 public int doEndTag() {
039 try {
040 SearchContainerRowTag<R> searchContainerRowTag =
041 (SearchContainerRowTag<R>)findAncestorWithClass(
042 this, SearchContainerRowTag.class);
043
044 ResultRow resultRow = searchContainerRowTag.getRow();
045
046 if (index <= -1) {
047 List<SearchEntry> searchEntries = resultRow.getEntries();
048
049 index = searchEntries.size();
050 }
051
052 ButtonSearchEntry buttonSearchEntry = new ButtonSearchEntry();
053
054 buttonSearchEntry.setAlign(getAlign());
055 buttonSearchEntry.setColspan(getColspan());
056 buttonSearchEntry.setCssClass(getCssClass());
057 buttonSearchEntry.setHref(String.valueOf(getHref()));
058 buttonSearchEntry.setName(LanguageUtil.get(request, getName()));
059 buttonSearchEntry.setValign(getValign());
060
061 resultRow.addSearchEntry(index, buttonSearchEntry);
062
063 return EVAL_PAGE;
064 }
065 finally {
066 index = -1;
067
068 if (!ServerDetector.isResin()) {
069 align = SearchEntry.DEFAULT_ALIGN;
070 colspan = SearchEntry.DEFAULT_COLSPAN;
071 cssClass = SearchEntry.DEFAULT_CSS_CLASS;
072 _href = null;
073 name = StringPool.BLANK;
074 valign = SearchEntry.DEFAULT_VALIGN;
075 }
076 }
077 }
078
079 @Override
080 public int doStartTag() throws JspException {
081 SearchContainerRowTag<R> searchContainerRowTag =
082 (SearchContainerRowTag<R>)findAncestorWithClass(
083 this, SearchContainerRowTag.class);
084
085 if (searchContainerRowTag == null) {
086 throw new JspTagException(
087 "Requires liferay-ui:search-container-row");
088 }
089
090 if (!searchContainerRowTag.isHeaderNamesAssigned()) {
091 List<String> headerNames = searchContainerRowTag.getHeaderNames();
092
093 headerNames.add(StringPool.BLANK);
094 }
095
096 return EVAL_BODY_INCLUDE;
097 }
098
099 public Object getHref() {
100 if (_href instanceof PortletURL) {
101 _href = _href.toString();
102 }
103
104 return _href;
105 }
106
107 public void setHref(Object href) {
108 _href = href;
109 }
110
111 private Object _href;
112
113 }