Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Armaz Mellati
Problems embedding the search portlet in the Theme
August 1, 2011 5:40 AM
Answer

Armaz Mellati

Rank: Junior Member

Posts: 63

Join Date: October 30, 2009

Recent Posts

Hi

I try to embed the Search-portlet (Not the Web content Search, but the Seach portlet that can search everything , the portlet with ID 3) in to the theme. I would believe that's a common use-case. However I can not make it to work properly. I am using Liferay 6.0.6 CE

The portlet shows nicely. I can write inn the search criteria, but when I hit the Enter, it looks pretty wired. It seems the portlet in the theme gets maximized and removed from the theme. Another strange thing is that it displays the search result and at the same time displays "You do not have the roles required to access this portlet. ".

I partly understand why all this happens. It is because the portlet in the theme gets maximized itself to show the results. However the results should be displayed by another portlet ? On the other hand I get the error message because the page does not have defined the Search portlet on the page, and that seems Liferay does not allow. If I add the search portlet to the page (in addition to the portlet in the theme), I get two search-results on top of each-other.

However my question is remains, how am I supposed to embed the Search-portlet in the theme so hat the user can do a search no matter which page he/she is on ? If anybody has done it in Liferay 6.x, please let me know.


Regards
Armaz Mellati
Armaz Mellati
RE: Problems embedding the search portlet in the Theme
August 2, 2011 4:16 AM
Answer

Armaz Mellati

Rank: Junior Member

Posts: 63

Join Date: October 30, 2009

Recent Posts

After many hours searching/trying and failing I found how that is to be done.

You are not supposed to use the search-portlet in the theme. All you need to do is to set up a regular form with the right action attribute. This way you just send your search-criteria to the Search-portlet and have it display the result. This is how it is done by Liferay when using the $theme.journalContentSearch(). The trick is however how to generate the right action-url. This is what I did :

Within navigation.vm added this line where I wanted the search to appear.
1$theme.include($themeServletContext, "/jsps/my_search.jsp")

Created the file "my_search.jsp" and filled it with the following (I left out all the imports part)
 1
 2<%
 3PortletRequest portletRequest = (PortletRequest)request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);
 4PortletResponse portletResponse = (PortletResponse)request.getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);
 5String namespace = StringPool.BLANK;
 6boolean useNamespace = GetterUtil.getBoolean((String)request.getAttribute("aui:form:useNamespace"), true);
 7if ((portletResponse != null) && useNamespace) {
 8    namespace = portletResponse.getNamespace();
 9}
10
11String currentURL = PortalUtil.getCurrentURL(request);
12String defaultKeywords = LanguageUtil.get(pageContext, "search") + "....";
13String unicodeDefaultKeywords = UnicodeFormatter.toString(defaultKeywords);
14
15String keywords = ParamUtil.getString(request, namespace + "keywords", defaultKeywords);
16PortletURL portletURL = PortletURLFactoryUtil.create(request, PortletKeys.SEARCH, plid, PortletRequest.RENDER_PHASE);
17
18portletURL.setWindowState(WindowState.MAXIMIZED);
19portletURL.setPortletMode(PortletMode.VIEW);
20
21portletURL.setParameter("struts_action", "/search/search");
22
23long groupId = ParamUtil.getLong(request, "groupId");
24Group group = themeDisplay.getScopeGroup();
25String format = ParamUtil.getString(request, "format");
26%>
27
28<form action="<%= portletURL.toString() %>" class="aui-form" method="post" name="<%= namespace %>fm" onSubmit="submitForm(this); return false;">
29<aui:input name="format" type="hidden" value="<%= format %>" />
30
31<%
32String taglibOnBlur = "if (this.value == '') { this.value = '" + unicodeDefaultKeywords + "'; }";
33String taglibOnFocus = "if (this.value == '" + unicodeDefaultKeywords + "') { this.value = ''; }";
34%>
35    <aui:fieldset>
36        <aui:input inlineField="<%= true %>" label="" name="keywords" size="30" onBlur="<%= taglibOnBlur %>" onFocus="<%= taglibOnFocus %>" title="search-web-content" type="text" value="<%= HtmlUtil.escape(keywords) %>" />
37
38        <aui:select inlineField="<%= true %>" label="" name="groupId">
39            <aui:option label="everything" selected="<%= groupId == 0 %>" value="0" />
40            <aui:option label='<%= "this-" + (group.isOrganization() ? "organization" : "community") %>' selected="<%= groupId != 0 %>" value="<%= group.getGroupId() %>" />
41        </aui:select>
42
43        <aui:input align="absmiddle" border="0" inlineField="<%= true %>" label="" name="search" src='<%= themeDisplay.getPathThemeImages() + "/common/search.png" %>' title="search" type="image" />
44    </aui:fieldset>
45
46</form>


But, this will result in an error message like this "You do not have the roles required to access this portlet. ". After some hours frustration I found that this is a new security in Liferay 6 to prevent Cross-site scripting. The solution is to white-list the portlet or the Struts-action in your portal-ext.properties

1portlet.add.default.resource.check.whitelist = 3


Hope this will prevent some others to go through all the trouble I had to go through.
Oliver Bayer
RE: Problems embedding the search portlet in the Theme
August 2, 2011 5:11 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 867

Join Date: February 18, 2009

Recent Posts

Hi Armaz,

can't you use the following tag?

1$theme.search()

At least in 5.2.3 it worked that easy way emoticon.

Greets Oli
Shuaib K
RE: Problems embedding the search portlet in the Theme
October 3, 2011 3:49 AM
Answer

Shuaib K

Rank: New Member

Posts: 19

Join Date: August 6, 2011

Recent Posts

Could you please list all the imports you used in the my_search.jsp? Thanks much!
Armaz Mellati
RE: Problems embedding the search portlet in the Theme
October 4, 2011 12:32 AM
Answer

Armaz Mellati

Rank: Junior Member

Posts: 63

Join Date: October 30, 2009

Recent Posts

What we use now is somewhat simpler. Here is our whole my_search.jsp


<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>

<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%@ page import="com.liferay.portal.model.Group" %>

<liferay-theme:defineObjects />

<!-- (eventuelt)forrige valgte groupid -->
<%
long groupId = ParamUtil.getLong(request, "groupId");
Group group = themeDisplay.getScopeGroup();
String format = ParamUtil.getString(request, "format");
String current_url=ParamUtil.getString(request, "CURRENT_URL"); // I think current_url gets empty here, but it works just fine
String actionURL=current_url+"?p_p_id=3&p_p_lifecycle=0&p_p_state=maximized&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=3&_3_struts_action=%2Fsearch%2Fsearch";

%>


<div class="heading-search">

<aui:form action="<%= actionURL %>" method="post" name="fm" >
<aui:input name="format" type="hidden" value="<%= format %>" />

<aui:fieldset>
<aui:input inlineField="<%= true %>" label="" name="keywords" size="30" value="" />

<aui:input type="hidden" name="groupId" value="<%= group.getGroupId() %>" />

<aui:input align="absmiddle" border="0" inlineField="<%= true %>" label="" name="search" src='<%= themeDisplay.getPathThemeImages() + "/common/search.png" %>' title="search" type="image" />
</aui:fieldset>
</aui:form>

</div>

Shuaib K
RE: Problems embedding the search portlet in the Theme
October 4, 2011 5:07 AM
Answer

Shuaib K

Rank: New Member

Posts: 19

Join Date: August 6, 2011

Recent Posts

Hi there,
Thanks for the quick reply. One question though. I see that you have used taglibs where the uri points to Internet sites. The server that I am testing Liferay on does not have Internet access. Would this be a problem?
Armaz Mellati
RE: Problems embedding the search portlet in the Theme
October 4, 2011 6:00 AM
Answer

Armaz Mellati

Rank: Junior Member

Posts: 63

Join Date: October 30, 2009

Recent Posts

No I don't think so. those are just namespace uri.
Sujeet Rai
RE: Problems embedding the search portlet in the Theme
May 26, 2013 3:24 AM
Answer

Sujeet Rai

Rank: New Member

Posts: 8

Join Date: October 21, 2012

Recent Posts

Where I should create " my_search.jsp". can u give path. I my using liferay developer studio.