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