掲示板

Changing search results links behaviour

thumbnail
12年前 に M. Garcia によって更新されました。

Changing search results links behaviour

Regular Member 投稿: 107 参加年月日: 11/05/17 最新の投稿
Hello,

I'm trying to change the -awful- links behaviour from Search portlet results.

By default, the Web Contents links in the results list opens a popup and display the article alone in the popup.

What I'm trying to do is open the web content in an asset publisher in a specific page (my "News" page).
I've already managed to do this from an asset publisher on one page to another asset publisher on another page.

But I'm struggling to make it work from the search results list.

This is the code that WORKS, from the my-display-style.jsp of the hook I did for Asset Publisher, that displays content in an other AssetPublisher in another page :
AssetEntry assetEntry = (AssetEntry)request.getAttribute("view.jsp-assetEntry");
AssetRendererFactory assetRendererFactory = (AssetRendererFactory)request.getAttribute("view.jsp-assetRendererFactory");
AssetRenderer assetRenderer = (AssetRenderer)request.getAttribute("view.jsp-assetRenderer");
...
<liferay-portlet:renderurl var="viewFullContentURL" portletname="101_INSTANCE_7rI2" plid="10501">
	<liferay-portlet:param name="struts_action" value="/asset_publisher/view_content"></liferay-portlet:param>
	<liferay-portlet:param name="assetEntryId" value="<%= String.valueOf(assetEntry.getEntryId()) %>"></liferay-portlet:param>
	<liferay-portlet:param name="type" value="<%= assetRendererFactory.getType() %>"></liferay-portlet:param>
&lt;%
if (Validator.isNotNull(assetRenderer.getUrlTitle())) {
	if (assetRenderer.getGroupId() != scopeGroupId) {
%&gt;
		<liferay-portlet:param name="groupId" value="<%= String.valueOf(assetRenderer.getGroupId()) %>"></liferay-portlet:param>
&lt;%
	}
%&gt;
	<liferay-portlet:param name="urlTitle" value="<%= assetRenderer.getUrlTitle() %>"></liferay-portlet:param>
&lt;%
}
%&gt;
</liferay-portlet:renderurl>

So, there are some parameters using AssetRenderer and AssetRendererFactory, retrieved in the request attributes.

Now here is the code I'm hooking in search.jsp from the search portlet :
  /* Search Result is a Web Content */
					JournalArticle article = JournalArticleLocalServiceUtil.getArticle(entryGroupId, articleId);
                                         ...
					String className = "com.liferay.portlet.journal.model.JournalArticle";
					long classPK = article.getResourcePrimKey();
					AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(className, classPK);
%&gt;					
					<liferay-portlet:renderurl var="viewFullContentURL" portletname="101_INSTANCE_7rI2" plid="10501">
					<liferay-portlet:param name="struts_action" value="/asset_publisher/view_content"></liferay-portlet:param>
					<liferay-portlet:param name="assetEntryId" value="<%= String.valueOf(assetEntry.getEntryId()) %>"></liferay-portlet:param>
					<liferay-portlet:param name="groupId" value="<%= String.valueOf(assetEntry.getGroupId()) %>"></liferay-portlet:param>
					</liferay-portlet:renderurl>

This links redirects me on the page, but with a NullPointerException, AssetPublisher portlet maximised and empty :
09:30:01,222 ERROR [jsp:1237]
java.lang.NullPointerException
        at org.apache.jsp.html.portlet.asset_005fpublisher.view_005fcontent_jsp.
_jspService(view_005fcontent_jsp.java:1176)


The only differences between the links I'm constructing (the one that work, and the one I'm trying) are the parameters "type" and "urlTitle" which are provided by AssetRenderer and AssetRendererFactory.
So now the questions :
  • Do I need those parameters to make it work ?
  • If I need those parameters, how can I construct them as I can't retrieve AssetRenderer and AssetRendererFactory from the request attributes ?
  • How can I set the portlet state parameter, as for now it goes "maximised", and I want it to be "normal" ? I tried to set a p_p_state parameter in the renderURL but it stays maximised.


I hope I made it clear, thanks a lot for helping ! =)
thumbnail
12年前 に M. Garcia によって更新されました。

RE: Changing search results links behaviour (回答)

Regular Member 投稿: 107 参加年月日: 11/05/17 最新の投稿
Okey, I managed to display web contents in the asset publisher on the page I want :
					String className = "com.liferay.portlet.journal.model.JournalArticle";
					long classPK = article.getResourcePrimKey();
					
					AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(className, classPK);
					AssetRendererFactory assetRendererFactory = AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(className);
					AssetRenderer assetRenderer = assetRendererFactory.getAssetRenderer(classPK);
%&gt;					
					<liferay-portlet:renderurl var="viewFullContentURL" portletname="101_INSTANCE_7rI2" plid="10501">
					<liferay-portlet:param name="struts_action" value="/asset_publisher/view_content"></liferay-portlet:param>
					<liferay-portlet:param name="assetEntryId" value="<%= String.valueOf(assetEntry.getEntryId()) %>"></liferay-portlet:param>
					<liferay-portlet:param name="type" value="<%= assetRendererFactory.getType() %>"></liferay-portlet:param>
&lt;%
					if (Validator.isNotNull(assetRenderer.getUrlTitle())) {
						if (assetRenderer.getGroupId() != scopeGroupId) {
%&gt;
							<liferay-portlet:param name="groupId" value="<%= String.valueOf(assetRenderer.getGroupId()) %>"></liferay-portlet:param>
&lt;%
						}
%&gt;
						<liferay-portlet:param name="urlTitle" value="<%= assetRenderer.getUrlTitle() %>"></liferay-portlet:param>
&lt;%
					}
%&gt;
					</liferay-portlet:renderurl>

Now I have a little issue : the Asset publisher is in "maximised" state, I think this is because the search portlet displaying result is in maximised state, and it somehow stay as a parameter.

How can I set the state of the portlet to be normal ? I tried setting a parameter in the URL like this :
<liferay-portlet:param name="p_p_state" value="normal"></liferay-portlet:param>

But it remains maximised.

Any idea ? I'm almost done ! =)
thumbnail
12年前 に M. Garcia によって更新されました。

RE: Changing search results links behaviour (回答)

Regular Member 投稿: 107 参加年月日: 11/05/17 最新の投稿
Okey !

<liferay-portlet:renderurl windowstate="<%= WindowState.NORMAL.toString() %>" ...></liferay-portlet:renderurl>


Hope this helps anyone in the same case =)