Foros de discusión

DisplayTerms problem in search page

thumbnail
Abdollah Esmaeilpour, modificado hace 14 años.

DisplayTerms problem in search page

Junior Member Mensajes: 60 Fecha de incorporación: 22/08/09 Mensajes recientes
Hi everybody

I wrote a portlet for view and search products. Its main page named view.jsp and is similar to view_organization.jsp of liferay. This is my code in file view.jsp:

<%@include file="/html/portlet/idlp/init.jsp"%>
<%
     
    PortletURL portletURL = renderResponse.createRenderURL();
    portletURL.setWindowState(WindowState.MAXIMIZED);
    portletURL.setParameter("struts_action", "/idlp/a-z_list/view");
%>

<form class="uni-form" action="<%= portletURLString %>" method="get" name="<portlet:namespace />fm" onSubmit="submitForm(this); return false;">

<liferay-ui:search-container searchcontainer="<%=new ProductSearch(renderRequest, portletURL)%>">
	
	<liferay-ui:search-form page="/html/portlet/idlp/a-z_list/product_search.jsp" />
	
	    &lt;%
	    ProductSearchTerms searchTerms = (ProductSearchTerms)searchContainer.getSearchTerms();
	    %&gt;
	    <liferay-ui:search-container-results>
	        &lt;%@ include file="/html/portlet/idlp/a-z_list/product_search_results.jspf" %&gt;
	    </liferay-ui:search-container-results>
	
       <liferay-ui:search-container-row classname="com.rose.idlp.model.Product" escapedmodel="<%= true %>" keyproperty="productId" modelvar="product">
            <portlet:renderurl var="rowURL">
                <portlet:param name="redirect" value="<%= searchContainer.getIteratorURL().toString() %>" />
                <portlet:param name="organizationId" value="<%= String.valueOf(product.getProductId()) %>" />
            </portlet:renderurl>
        
            &lt;%@ include file="/html/portlet/idlp/a-z_list/search_columns.jspf" %&gt;
        </liferay-ui:search-container-row>	
	    </liferay-ui:search-container></form>
<br><br> <liferay-ui:search-iterator />


ProductSearch is a class extended from SearchContainer and works fine

Another important file is "/html/portlet/idlp/a-z_list/product_search.jsp". It is its code :

&lt;%@include file="/html/portlet/idlp/init.jsp"%&gt;

&lt;%
themeDisplay.setIncludeServiceJs(true);
ProductSearch searchContainer = (ProductSearch)request.getAttribute("liferay-ui:search:searchContainer");
ProductDisplayTerms displayTerms = (ProductDisplayTerms)searchContainer.getDisplayTerms();
%&gt;

<liferay-ui:search-toggle id="toggle_id_idlp_atoz_list_search" displayterms="<%= displayTerms %>" buttonlabel="search">
    <table class="lfr-table">
    <tbody><tr>
        <td>
            <liferay-ui:message key="title" />
        </td>
        <td>
            <liferay-ui:message key="issn-isbn" />
        </td>
        <td>
            <liferay-ui:message key="publisher" />
        </td>
        <td>
            <liferay-ui:message key="subject" />
        </td>
        <td>
            <liferay-ui:message key="rank" />
        </td>
        <td>
            <liferay-ui:message key="access-link" />
        </td>
    </tr>
    <tr>
        <td>
            <input name="<portlet:namespace /><%= displayTerms.TITLE %>" size="20" type="text" value="<%= HtmlUtil.escape(displayTerms.getTitle()) %>">
        </td>
        <td>
            <input name="<portlet:namespace /><%= displayTerms.ISSN_ISBN %>" size="20" type="text" value="<%= HtmlUtil.escape(displayTerms.getIssn_isbn()) %>">
        </td>
        <td>
            <input name="<portlet:namespace /><%= displayTerms.PUBLISHER %>" size="20" type="text" value="<%= HtmlUtil.escape(displayTerms.getPublisher()) %>">
        </td>
        <td>
            <input name="<portlet:namespace /><%= displayTerms.SUBJECT %>" size="20" type="text" value="<%= HtmlUtil.escape(displayTerms.getSubject()) %>">
        </td>
        <td>
            <input name="<portlet:namespace /><%= displayTerms.RANK %>" size="20" type="text" value="<%= HtmlUtil.escape(displayTerms.getRank()) %>">
        </td>
        <td>
            <input name="<portlet:namespace /><%= displayTerms.ACCESS_LINK %>" size="20" type="text" value="<%= HtmlUtil.escape(displayTerms.getAccessLink()) %>">
        </td>
    </tr>
    </tbody></table>
</liferay-ui:search-toggle>


searchTerms is an object of class ProductSearchTerms that is:


public class ProductSearchTerms extends ProductDisplayTerms {

	public ProductSearchTerms(PortletRequest portletRequest) {
		super(portletRequest);
		title = DAOParamUtil.getLike(portletRequest, TITLE);
		issn_isbn = DAOParamUtil.getString(portletRequest, ISSN_ISBN);
		publisher = DAOParamUtil.getLike(portletRequest, PUBLISHER);
		subject = DAOParamUtil.getString(portletRequest, SUBJECT);
		rank = DAOParamUtil.getString(portletRequest, ACCESS_LINK);
		accessLink = DAOParamUtil.getString(portletRequest, RANK);
		rating = DAOParamUtil.getString(portletRequest, RATING);
		type = DAOParamUtil.getString(portletRequest, TYPE);
	}
}


final important file is /html/portlet/idlp/a-z_list/product_search_results.jspf. it is its code:

&lt;%
if (searchTerms.isAdvancedSearch()) {
	results = ProductLocalServiceUtil.search(searchTerms.getTitle(), searchContainer.getStart(), searchContainer.getEnd(), searchContainer.getOrderByComparator());
}
else {
	results = ProductLocalServiceUtil.search(searchTerms.getTitle(), searchContainer.getStart(), searchContainer.getEnd(), searchContainer.getOrderByComparator());
}

if (searchTerms.isAdvancedSearch()) {
	total = ProductLocalServiceUtil.searchCount(searchTerms.getTitle());
}
else {
	total = ProductLocalServiceUtil.searchCount(searchTerms.getTitle());
}

pageContext.setAttribute("results", results);
pageContext.setAttribute("total", total);
%&gt;


As you see, ProductLocalServiceUtil.search() function gets search parameter "title" by calling searchTerms.getTitle() method.
For first time it works fine and search all the products i.e. when no search parameter specified all things are OK. But if I give an input for example I specify "title" for searching products with specified title, it gets all of the products like first time. I understood that searchTerms.getTitle() returns null.

What is wrong?

I attached my portlet image

Archivos adjuntos:

thumbnail
Abdollah Esmaeilpour, modificado hace 14 años.

RE: DisplayTerms problem in search page

Junior Member Mensajes: 60 Fecha de incorporación: 22/08/09 Mensajes recientes
I found the root of problem. renderRequest object does not contain parameter title=search_term (let search_term be term to be searched by user). But I don't know where and how I can set this parameter.
thumbnail
Abdollah Esmaeilpour, modificado hace 14 años.

RE: DisplayTerms problem in search page

Junior Member Mensajes: 60 Fecha de incorporación: 22/08/09 Mensajes recientes
It is solved. I change action type from "get" to "post"
thumbnail
Ivano Carrara, modificado hace 12 años.

RE: DisplayTerms problem in search page

Expert Mensajes: 345 Fecha de incorporación: 3/07/05 Mensajes recientes
Hi Abdollah,

Please, could you help me ?

In my portlet plugin, to search Liferay's portal users, I'm trying to use the below code:

<%@ include file="/html/portlet/enterprise_admin/init.jsp" %>

<%
UserSearch searchContainer = (UserSearch)request.getAttribute("liferay-ui:search:searchContainer");
UserDisplayTerms displayTerms = (UserDisplayTerms)searchContainer.getDisplayTerms();
%>

BUT I get errors because the "<%@ include file="/html/portlet/enterprise_admin/init.jsp" %>" is unresolved ....

Please, could you help me ?

Thank you in advance !

Ivano C.
thumbnail
Abdollah Esmaeilpour, modificado hace 9 años.

RE: DisplayTerms problem in search page

Junior Member Mensajes: 60 Fecha de incorporación: 22/08/09 Mensajes recientes
Your jsp is in plginSDK, so you cannot point to a jsp in root path of liferay. You can use hook.