001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }