17 April, 2012

Use of liferay-ui:search-toggle - with Basic or Advanced Search

Hello Guys,
I met with a interesting scenario, I was using <liferay-ui:search-toggle> tag, and my requirement was to show only advanced search and no basic search.
But by default <liferay-ui:search-toggle> will show basic search unless and until user clicks the advanced search at least once. I tried all possible ways and finally found the solution, this what i did to make my <liferay-ui:search-toggle> show only "Advanced Search" without "Basic" search toggle link.

So what we need to do is,

  1. We need to override the isAdvancedSearch method of the XDisplayTerms class to always return true, where "X" your class prefix e.g.ArticleDisplayTerms which extends form com.liferay.portal.kernel.dao.search.DisplayTerms
  2. Update your *_search.jsp which has the <liferay-ui:search-toggle> with the following piece of code

style type="text/css">
.toggle-link {
    display: none;
This style overriding will prevent the "<<Basic" search link form being displayed, the next piece of  code snippet will make the "Advanced" search displayed by default, we are a kind of triggering the Search link click
String key = "<replace with the id of your <liferay-ui:search-toggle> tag";
SessionClicks.put(request, key,"advanced");
The key piece of code which does sends signal to the underlying liferay code to show only "advanced" is SessionClicks.put(request, key,"advanced");

The same could be achieved when we want to display only basic search and no advanced search just by changing the "advanced" to "basic"

That is it, once we have done with this our <liferay-ui:search-toggle> will always display only "Advanced"  or  "Basic" search

Hope this will be very useful when you come across the same scenario.

Popular Posts

Featured Post

Liferay 7.3 compatibility matrix

Compatibility Matrix Liferay's general policy is to test Liferay Portal CE against newer major releases of operating systems, open s...