Fórumok

Creating a PortletURL from scratch...

Nick Straguzzi, módosítva 11 év-val korábban

Creating a PortletURL from scratch...

New Member Bejegyzések: 15 Csatlakozás dátuma: 2012.05.11. Legújabb bejegyzések
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
thumbnail
Sreeraj AV, módosítva 11 év-val korábban

RE: Creating a PortletURL from scratch...

Regular Member Bejegyzések: 239 Csatlakozás dátuma: 2010.04.27. Legújabb bejegyzések
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.


				StringBundler rowSB = new StringBundler();

				if (portletId.equals(PortletKeys.JOURNAL) || (portletId.equals(PortletKeys.SEARCH) && entryClassName.equals(JournalArticle.class.getName()))) {
					String articleId = el.elementText(OpenSearchUtil.getQName(Field.ENTRY_CLASS_PK, OpenSearchUtil.LIFERAY_NAMESPACE));

					JournalArticle article = JournalArticleLocalServiceUtil.getArticle(entryGroupId, articleId);

					if (DateUtil.compareTo(article.getDisplayDate(), new Date()) > 0) {
						total--;

						continue;
					}

					rowSB.append("<a class="\&quot;entry-title\&quot;" href="\&quot;&quot;);" rowsb.append(entryhref); rowsb.append("\" target="\&quot;_blank\&quot;">");
					
/************************NOUS Modification Starts***************************/

				}else if(portletId.equals(PortletKeys.DIRECTORY)){         
					long userId = Long.parseLong(el.elementText(OpenSearchUtil.getQName(Field.ENTRY_CLASS_PK, OpenSearchUtil.LIFERAY_NAMESPACE)));
					User nousUser = UserLocalServiceUtil.getUser(userId);
					rowSB.append("</a><a class="\&quot;entry-title\&quot;" href="\&quot;&quot;);" rowsb.append(noususer.getdisplayurl(themedisplay)); rowsb.append("\">");
					
/************************NOUS Modification ends***************************/

				}else{
					rowSB.append("</a><a class="\&quot;entry-title\&quot;" href="\&quot;&quot;);" rowsb.append(entryhref); rowsb.append("\">");
				}

</a>

Mellékletek:

Nick Straguzzi, módosítva 11 év-val korábban

RE: Creating a PortletURL from scratch...

New Member Bejegyzések: 15 Csatlakozás dátuma: 2012.05.11. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: Creating a PortletURL from scratch...

New Member Bejegyzések: 15 Csatlakozás dátuma: 2012.05.11. Legújabb bejegyzések
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