Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Nick Straguzzi
Creating a PortletURL from scratch...
December 6, 2012 2:29 PM
Answer

Nick Straguzzi

Rank: New Member

Posts: 15

Join Date: May 11, 2012

Recent Posts

Folks,

I need help doing something that should be very easy, except it has me stumped. I need to create a PortletURL to a particular page in my Liferay portal. However, I will *not* have a portlet request, action request, http request, or any other sort of request. I know the URL to the page I want to take the user to, but I need to express it as a PortletURL for reasons discussed below.

Details:
I've created a custom indexer for a class of "dashboards" in our application.
These dashboards are pages of the form: http://mysite/web/community/dashboard_type?dashboard_id=###
I created an Indexer class that works fine. Now, for the "hits", I need to create a Summary object using doGetSummary().
The Summary constructor takes three parameters: title, summary text, and portlet URL.
I am given the current portlet URL as an argument to doGetSummary, but it is for a custom search result page that's irrelevant to the target dashboard page.

In short, if the user selects a particular dashboard from the search results, I need to send him to a completely different page in the portal.
But, I have to express it as a PortletURL object because that's what the Summary class demands.

So how do I do it?
(Yes, I am aware I could do this through Struts, but I am trying very hard to avoid that. I just want to send the user to a URL that I know.)

Regards,
Nick
Sreeraj AV
RE: Creating a PortletURL from scratch...
December 7, 2012 2:38 AM
Answer

Sreeraj AV

Rank: Regular Member

Posts: 233

Join Date: April 26, 2010

Recent Posts

Nick Straguzzi:
Folks,

I need help doing something that should be very easy, except it has me stumped. I need to create a PortletURL to a particular page in my Liferay portal. However, I will *not* have a portlet request, action request, http request, or any other sort of request. I know the URL to the page I want to take the user to, but I need to express it as a PortletURL for reasons discussed below.

Details:
I've created a custom indexer for a class of "dashboards" in our application.
These dashboards are pages of the form: http://mysite/web/community/dashboard_type?dashboard_id=###
I created an Indexer class that works fine. Now, for the "hits", I need to create a Summary object using doGetSummary().
The Summary constructor takes three parameters: title, summary text, and portlet URL.
I am given the current portlet URL as an argument to doGetSummary, but it is for a custom search result page that's irrelevant to the target dashboard page.

In short, if the user selects a particular dashboard from the search results, I need to send him to a completely different page in the portal.
But, I have to express it as a PortletURL object because that's what the Summary class demands.

So how do I do it?
(Yes, I am aware I could do this through Struts, but I am trying very hard to avoid that. I just want to send the user to a URL that I know.)

Regards,
Nick


I think you can customize search portlet JSP files using Hooks for this. I have done something similar in LR 6.0.5. When searching for a user, on clicking the user link it should be navigate to particular users public pages instead of navigating to Directory Portlet.

 1
 2                StringBundler rowSB = new StringBundler();
 3
 4                if (portletId.equals(PortletKeys.JOURNAL) || (portletId.equals(PortletKeys.SEARCH) && entryClassName.equals(JournalArticle.class.getName()))) {
 5                    String articleId = el.elementText(OpenSearchUtil.getQName(Field.ENTRY_CLASS_PK, OpenSearchUtil.LIFERAY_NAMESPACE));
 6
 7                    JournalArticle article = JournalArticleLocalServiceUtil.getArticle(entryGroupId, articleId);
 8
 9                    if (DateUtil.compareTo(article.getDisplayDate(), new Date()) > 0) {
10                        total--;
11
12                        continue;
13                    }
14
15                    rowSB.append("<a class=\"entry-title\" href=\"");
16                    rowSB.append(entryHref);
17                    rowSB.append("\" target=\"_blank\">");
18                   
19/************************NOUS Modification Starts***************************/
20
21                }else if(portletId.equals(PortletKeys.DIRECTORY)){         
22                    long userId = Long.parseLong(el.elementText(OpenSearchUtil.getQName(Field.ENTRY_CLASS_PK, OpenSearchUtil.LIFERAY_NAMESPACE)));
23                    User nousUser = UserLocalServiceUtil.getUser(userId);
24                    rowSB.append("<a class=\"entry-title\" href=\"");
25                    rowSB.append(nousUser.getDisplayURL(themeDisplay));
26                    rowSB.append("\">");
27                   
28/************************NOUS Modification ends***************************/
29
30                }else{
31                    rowSB.append("<a class=\"entry-title\" href=\"");
32                    rowSB.append(entryHref);
33                    rowSB.append("\">");
34                }
Attachments: search.jsp (14.4k)
Nick Straguzzi
RE: Creating a PortletURL from scratch...
December 7, 2012 6:53 AM
Answer

Nick Straguzzi

Rank: New Member

Posts: 15

Join Date: May 11, 2012

Recent Posts

Thank you Sreeraj. Hooking the portlet is indeed a possible workaround solution. However, I'd like to get the right URL coming out of Lucene, because the Search Results portlet is not necessarily the only place in my portal that I want to use the results. (For example, I want to allow the search results to be federated or used in an RSS feed, and in either case I need Liferay to return the "correct" URL directly.)

Does anyone have any ideas? I cannot believe it's this difficult to create a PortletURL from scratch in the Portlet 2.0 standards, but I can't find a solution.

Regards,
Nick
Nick Straguzzi
RE: Creating a PortletURL from scratch...
December 12, 2012 8:29 AM
Answer

Nick Straguzzi

Rank: New Member

Posts: 15

Join Date: May 11, 2012

Recent Posts

Two notes before this thread is put to bed, in case they are of use to anyone down the line....

(1) The way to create a PortletURL from scratch is, cunningly enough, to create your own class that implements the PortletURL interface.

(2) Even doing the above won't help you in Liferay if your goal is to do a complete (possibly external) redirect of a search result URL. The reason has to do with the way HitsOpenSearchImpl is coded. To cut to the chase: there's no way to override the portlet URL that is passed to you in doGetSummary(). Even though you must supply a PortletURL as an argument to the constructor of Summary, this value is never used. The calling routine ignores what you put there and uses its original PortletURL object come hell or high water. I think this is a bug, or at least a questionable implementation decision, and I'll open a JIRA ticket.

Regards,
Nick