001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.taglib.ui;
016    
017    import com.liferay.portal.kernel.dao.search.SearchContainer;
018    import com.liferay.taglib.util.IncludeTag;
019    
020    import javax.servlet.http.HttpServletRequest;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     */
025    public class SearchFormTag<R> extends IncludeTag {
026    
027            public void setSearchContainer(SearchContainer<?> searchContainer) {
028                    _searchContainer = searchContainer;
029            }
030    
031            public void setShowAddButton(boolean showAddButton) {
032                    _showAddButton = showAddButton;
033            }
034    
035            @Override
036            protected void cleanUp() {
037                    _searchContainer = null;
038                    _showAddButton = false;
039            }
040    
041            @Override
042            protected void setAttributes(HttpServletRequest request) {
043                    SearchContainerTag<R> searchContainerTag =
044                            (SearchContainerTag<R>)findAncestorWithClass(
045                                    this, SearchContainerTag.class);
046    
047                    if (searchContainerTag != null) {
048                            _searchContainer = searchContainerTag.getSearchContainer();
049                    }
050    
051                    request.setAttribute(
052                            "liferay-ui:search:searchContainer", _searchContainer);
053                    request.setAttribute(
054                            "liferay-ui:search:showAddButton", String.valueOf(_showAddButton));
055            }
056    
057            private SearchContainer<?> _searchContainer;
058            private boolean _showAddButton;
059    
060    }