Foren

create portletURL with class portletURLImpl and own portletId

Joerg Schaefer, geändert vor 15 Jahren.

create portletURL with class portletURLImpl and own portletId

Junior Member Beiträge: 60 Beitrittsdatum: 05.05.08 Neueste Beiträge
Hi, i want to create a portletURL in a JSP with the following statement:

PortletURL portletURL = new PortletURLImpl(request, "test-portlet", plid, PortletRequest.RENDER_PHASE);


But if i run the JSP, liferay logs the error "Portlet not found for 10106 test-portlet".
If i insert a portletId form the out-of-the-box liferay portlets, then it works fine.
The question is now.
Can i create a liferay-portletURL (portletURLImpl) with my own written portlets?

What i want to do is, if a user inserts a searchTerm at the top of the portal and clicks the search-image, then i want to forward to my own search-portlet. And the search-portlet should start maximized.

I don't know, how i can solve the problem with the standard javax.portlet.PortletURL in this case.

Thanks

Jörg
thumbnail
Jitendra Rajput, geändert vor 12 Jahren.

RE: create portletURL with class portletURLImpl and own portletId

Liferay Master Beiträge: 875 Beitrittsdatum: 07.01.11 Neueste Beiträge
I knw its too late reply ...
But you can retrieve PortletURL of any portlet by this way


HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(portletRequest);  
httpRequest = PortalUtil.getOriginalServletRequest(httpRequest)  
  
//Retrieve layout id of another portlet   
long plid = PortalUtil.getPlidFromPortletId(themeDisplay.getScopeGroupId(), portletID);  
  
PortletURL portletURL = PortletURLFactoryUtil.create(httpRequest ,portletId, plid ,PortletRequest.RENDER_PHASE);  
thumbnail
David García González, geändert vor 12 Jahren.

RE: create portletURL with class portletURLImpl and own portletId

Regular Member Beiträge: 127 Beitrittsdatum: 14.07.09 Neueste Beiträge
Hi, I am creating a new PortletURL, but the method toString() of PortletURL is throwing the following exception:

java.lang.IllegalStateException: Not allowed in a portlet
    at org.apache.struts2.portlet.servlet.PortletServletRequest.getServerPort(PortletServletRequest.java:618)
    at com.liferay.portal.util.PortalImpl.getPortalURL(PortalImpl.java:2199)
    at com.liferay.portal.util.PortalUtil.getPortalURL(PortalUtil.java:693)
    at com.liferay.portlet.PortletURLImpl.generateToString(PortletURLImpl.java:724)
    at com.liferay.portlet.PortletURLImpl.toString(PortletURLImpl.java:626)


Do you know any other way to generate a portlet url to another page?
thumbnail
Jitendra Rajput, geändert vor 12 Jahren.

RE: create portletURL with class portletURLImpl and own portletId

Liferay Master Beiträge: 875 Beitrittsdatum: 07.01.11 Neueste Beiträge
why you are using toString()...you can use it directly....

Can you please provide more details for your problm....
thumbnail
Sagar A Vyas, geändert vor 12 Jahren.

RE: create portletURL with class portletURLImpl and own portletId

Liferay Master Beiträge: 679 Beitrittsdatum: 17.04.09 Neueste Beiträge
Agree with Jitendra.

There is no need to use toString() , you can directly use it emoticon as below


<portlet:actionURL var="myActuinURL" name="myMethodName">
<portlet:param name="myParam" value="myParamVal"></portlet:param>
</portlet:actionURL>


<form action="<%=addReviewCommentURL %>" method="post" name="<portlet:namespace/>fm">
// Your stuff
</form>


Though you can use it like action="<%=addReviewCommentURL.toString() %>" .

I think error caused of this error is something else.

Please do verify it and let us know

Thanks,
Sagar Vyas
thumbnail
David García González, geändert vor 12 Jahren.

RE: create portletURL with class portletURLImpl and own portletId

Regular Member Beiträge: 127 Beitrittsdatum: 14.07.09 Neueste Beiträge
I am calling this method from a Struts 2 action of a jsr portlet to send an e-mail with a link to this portlet. This is the example code of the method.

private String generarURLActivacion(ThemeDisplay themeDisplay, String uuid)
			throws PortalException, SystemException {
		
		Layout layout = LayoutLocalServiceUtil.getFriendlyURLLayout(
				themeDisplay.getLayout().getGroupId(), false,
				"/activacion-cuenta");

		PortletURL portletURL = PortletURLFactoryUtil.create(servletRequest,
				"ActivacionRegistroClientes_WAR_RegistroClientesportlet", layout.getPlid(),
				PortletRequest.RENDER_PHASE);

		portletURL.setWindowState(WindowState.MAXIMIZED);
		portletURL.setPortletMode(PortletMode.VIEW);
		portletURL.setParameter(ParamKeys.UUID_PARAM, uuid);
	
		return portletURL.toString();
	}


Finally, I had to generate the url from the jsp and send it to the action in a hidden input.

Is there any better way?

Thanks!
neelam bhandari, geändert vor 12 Jahren.

RE: create portletURL with class portletURLImpl and own portletId

Regular Member Beiträge: 102 Beitrittsdatum: 16.08.11 Neueste Beiträge
Hi David,

I have written my portlet url code in the similar way as you have created for yours. But if I dont provide instance id in the portlet name request parameters do not have any values.
mine looks like this
PortletURL redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(request),
"propertyReceiver_WAR_Property_Reciever_INSTANCE_Im98",plid, PortletRequest.RENDER_PHASE);

I want to remove this Im98 from the url.

<instanceable>false </instanceable> in liferay-portlet.xml doest not solve the issue.

Many thanks
Neelam
thumbnail
Nagendra Kumar Busam, geändert vor 12 Jahren.

RE: create portletURL with class portletURLImpl and own portletId

Liferay Master Beiträge: 678 Beitrittsdatum: 07.07.09 Neueste Beiträge
Basically it should remove _INSTANCE_Im98 in your code if you make instanceable false in liferay-portlet.xml.

After deploying the changes did you try to remove the portlet with instance propertyReceiver_WAR_Property_Reciever_INSTANCE_Im98 & added once again
neelam bhandari, geändert vor 12 Jahren.

RE: create portletURL with class portletURLImpl and own portletId

Regular Member Beiträge: 102 Beitrittsdatum: 16.08.11 Neueste Beiträge
Hi Nagendra,
Just now I finished doing the aforementioned procedure.

Yes it works fine now.
Many thanks
Much appreciated
Neelam
thumbnail
Nagendra Kumar Busam, geändert vor 12 Jahren.

RE: create portletURL with class portletURLImpl and own portletId

Liferay Master Beiträge: 678 Beitrittsdatum: 07.07.09 Neueste Beiträge
Good to know it worked for you
GAURAV RAWAT, geändert vor 12 Jahren.

RE: create portletURL with class portletURLImpl and own portletId

New Member Beitrag: 1 Beitrittsdatum: 06.01.12 Neueste Beiträge
Jitendra Rajput:
I knw its too late reply ...
But you can retrieve PortletURL of any portlet by this way


HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(portletRequest);  
httpRequest = PortalUtil.getOriginalServletRequest(httpRequest)  
  
//Retrieve layout id of another portlet   
long plid = PortalUtil.getPlidFromPortletId(themeDisplay.getScopeGroupId(), portletID);  
  
PortletURL portletURL = PortletURLFactoryUtil.create(httpRequest ,portletId, plid ,PortletRequest.RENDER_PHASE);  


Thanks Jitendra ,helped me a lot
thumbnail
Jitendra Rajput, geändert vor 12 Jahren.

RE: create portletURL with class portletURLImpl and own portletId

Liferay Master Beiträge: 875 Beitrittsdatum: 07.01.11 Neueste Beiträge
thats cool emoticon