フォーラム

ホーム » Liferay Portal » English » 3. Development

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
M. Garcia
Changing search results links behaviour
2011/08/18 3:01
答え

M. Garcia

ランク: Regular Member

投稿: 107

参加年月日: 2011/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 :
 1AssetEntry assetEntry = (AssetEntry)request.getAttribute("view.jsp-assetEntry");
 2AssetRendererFactory assetRendererFactory = (AssetRendererFactory)request.getAttribute("view.jsp-assetRendererFactory");
 3AssetRenderer assetRenderer = (AssetRenderer)request.getAttribute("view.jsp-assetRenderer");
 4...
 5<liferay-portlet:renderURL var="viewFullContentURL" portletName="101_INSTANCE_7rI2" plid="10501">
 6    <liferay-portlet:param name="struts_action" value="/asset_publisher/view_content"></liferay-portlet:param>
 7    <liferay-portlet:param name="assetEntryId" value="<%= String.valueOf(assetEntry.getEntryId()) %>"></liferay-portlet:param>
 8    <liferay-portlet:param name="type" value="<%= assetRendererFactory.getType() %>"></liferay-portlet:param>
 9<%
10if (Validator.isNotNull(assetRenderer.getUrlTitle())) {
11    if (assetRenderer.getGroupId() != scopeGroupId) {
12%>
13        <liferay-portlet:param name="groupId" value="<%= String.valueOf(assetRenderer.getGroupId()) %>"></liferay-portlet:param>
14<%
15    }
16%>
17    <liferay-portlet:param name="urlTitle" value="<%= assetRenderer.getUrlTitle() %>"></liferay-portlet:param>
18<%
19}
20%>
21</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 :
 1  /* Search Result is a Web Content */
 2                    JournalArticle article = JournalArticleLocalServiceUtil.getArticle(entryGroupId, articleId);
 3                                         ...
 4                    String className = "com.liferay.portlet.journal.model.JournalArticle";
 5                    long classPK = article.getResourcePrimKey();
 6                    AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(className, classPK);
 7%>                   
 8                    <liferay-portlet:renderURL var="viewFullContentURL" portletName="101_INSTANCE_7rI2" plid="10501">
 9                    <liferay-portlet:param name="struts_action" value="/asset_publisher/view_content"></liferay-portlet:param>
10                    <liferay-portlet:param name="assetEntryId" value="<%= String.valueOf(assetEntry.getEntryId()) %>"></liferay-portlet:param>
11                    <liferay-portlet:param name="groupId" value="<%= String.valueOf(assetEntry.getGroupId()) %>"></liferay-portlet:param>
12                    </liferay-portlet:renderURL>

This links redirects me on the page, but with a NullPointerException, AssetPublisher portlet maximised and empty :
109:30:01,222 ERROR [jsp:1237]
2java.lang.NullPointerException
3        at org.apache.jsp.html.portlet.asset_005fpublisher.view_005fcontent_jsp.
4_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 ! =)
M. Garcia
RE: Changing search results links behaviour
2011/08/19 1:55
答え

M. Garcia

ランク: Regular Member

投稿: 107

参加年月日: 2011/05/17

最近の投稿

Okey, I managed to display web contents in the asset publisher on the page I want :
 1                    String className = "com.liferay.portlet.journal.model.JournalArticle";
 2                    long classPK = article.getResourcePrimKey();
 3                   
 4                    AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(className, classPK);
 5                    AssetRendererFactory assetRendererFactory = AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(className);
 6                    AssetRenderer assetRenderer = assetRendererFactory.getAssetRenderer(classPK);
 7%>                   
 8                    <liferay-portlet:renderURL var="viewFullContentURL" portletName="101_INSTANCE_7rI2" plid="10501">
 9                    <liferay-portlet:param name="struts_action" value="/asset_publisher/view_content"></liferay-portlet:param>
10                    <liferay-portlet:param name="assetEntryId" value="<%= String.valueOf(assetEntry.getEntryId()) %>"></liferay-portlet:param>
11                    <liferay-portlet:param name="type" value="<%= assetRendererFactory.getType() %>"></liferay-portlet:param>
12<%
13                    if (Validator.isNotNull(assetRenderer.getUrlTitle())) {
14                        if (assetRenderer.getGroupId() != scopeGroupId) {
15%>
16                            <liferay-portlet:param name="groupId" value="<%= String.valueOf(assetRenderer.getGroupId()) %>"></liferay-portlet:param>
17<%
18                        }
19%>
20                        <liferay-portlet:param name="urlTitle" value="<%= assetRenderer.getUrlTitle() %>"></liferay-portlet:param>
21<%
22                    }
23%>
24                    </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 :
1<liferay-portlet:param name="p_p_state" value="normal"></liferay-portlet:param>

But it remains maximised.

Any idea ? I'm almost done ! =)
M. Garcia
RE: Changing search results links behaviour
2011/08/19 2:06
答え

M. Garcia

ランク: Regular Member

投稿: 107

参加年月日: 2011/05/17

最近の投稿

Okey !

1<liferay-portlet:renderURL windowState="<%= WindowState.NORMAL.toString() %>" ...>


Hope this helps anyone in the same case =)