Foren

Problems embedding the search portlet in the Theme

thumbnail
Armaz Mellati, geändert vor 12 Jahren.

Problems embedding the search portlet in the Theme

Junior Member Beiträge: 96 Beitrittsdatum: 30.10.09 Neueste Beiträge
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
thumbnail
Armaz Mellati, geändert vor 12 Jahren.

RE: Problems embedding the search portlet in the Theme

Junior Member Beiträge: 96 Beitrittsdatum: 30.10.09 Neueste Beiträge
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.
$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)

<%
PortletRequest portletRequest = (PortletRequest)request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);
PortletResponse portletResponse = (PortletResponse)request.getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);
String namespace = StringPool.BLANK;
boolean useNamespace = GetterUtil.getBoolean((String)request.getAttribute("aui:form:useNamespace"), true);
if ((portletResponse != null) && useNamespace) {
	namespace = portletResponse.getNamespace();
}

String currentURL = PortalUtil.getCurrentURL(request);
String defaultKeywords = LanguageUtil.get(pageContext, "search") + "....";
String unicodeDefaultKeywords = UnicodeFormatter.toString(defaultKeywords);

String keywords = ParamUtil.getString(request, namespace + "keywords", defaultKeywords);
PortletURL portletURL = PortletURLFactoryUtil.create(request, PortletKeys.SEARCH, plid, PortletRequest.RENDER_PHASE);

portletURL.setWindowState(WindowState.MAXIMIZED);
portletURL.setPortletMode(PortletMode.VIEW);

portletURL.setParameter("struts_action", "/search/search");

long groupId = ParamUtil.getLong(request, "groupId");
Group group = themeDisplay.getScopeGroup();
String format = ParamUtil.getString(request, "format");
%>

<form action="<%= portletURL.toString() %>" class="aui-form" method="post" name="<%= namespace %>fm" onSubmit="submitForm(this); return false;">
<aui:input name="format" type="hidden" value="<%= format %>" />

&lt;%
String taglibOnBlur = "if (this.value == '') { this.value = '" + unicodeDefaultKeywords + "'; }";
String taglibOnFocus = "if (this.value == '" + unicodeDefaultKeywords + "') { this.value = ''; }";
%&gt;
	<aui:fieldset>
		<aui:input inlineField="<%= true %>" label="" name="keywords" size="30" onBlur="<%= taglibOnBlur %>" onFocus="<%= taglibOnFocus %>" title="search-web-content" type="text" value="<%= HtmlUtil.escape(keywords) %>" />

		<aui:select inlinefield="<%= true %>" label="" name="groupId">
			<aui:option label="everything" selected="<%= groupId == 0 %>" value="0" />
			<aui:option label="<%= &quot;this-&quot; + (group.isOrganization() ? &quot;organization&quot; : &quot;community&quot;) %>" selected="<%= groupId != 0 %>" value="<%= group.getGroupId() %>" />
		</aui:select>

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

</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

portlet.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, geändert vor 12 Jahren.

RE: Problems embedding the search portlet in the Theme

Liferay Master Beiträge: 894 Beitrittsdatum: 18.02.09 Neueste Beiträge
Hi Armaz,

can't you use the following tag?

$theme.search()

At least in 5.2.3 it worked that easy way emoticon.

Greets Oli
Shuaib K, geändert vor 12 Jahren.

RE: Problems embedding the search portlet in the Theme

New Member Beiträge: 19 Beitrittsdatum: 06.08.11 Neueste Beiträge
Could you please list all the imports you used in the my_search.jsp? Thanks much!
thumbnail
Armaz Mellati, geändert vor 12 Jahren.

RE: Problems embedding the search portlet in the Theme

Junior Member Beiträge: 96 Beitrittsdatum: 30.10.09 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: Problems embedding the search portlet in the Theme

New Member Beiträge: 19 Beitrittsdatum: 06.08.11 Neueste Beiträge
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?
thumbnail
Armaz Mellati, geändert vor 12 Jahren.

RE: Problems embedding the search portlet in the Theme

Junior Member Beiträge: 96 Beitrittsdatum: 30.10.09 Neueste Beiträge
No I don't think so. those are just namespace uri.
thumbnail
Sujeet Rai, geändert vor 10 Jahren.

RE: Problems embedding the search portlet in the Theme

New Member Beiträge: 9 Beitrittsdatum: 22.10.12 Neueste Beiträge
Where I should create " my_search.jsp". can u give path. I my using liferay developer studio.