Fórum

Link Asset Publisher to a custom portlet

Dipesh Sahu, modificado 12 Anos atrás.

Link Asset Publisher to a custom portlet

New Member Postagens: 10 Data de Entrada: 24/07/11 Postagens Recentes
Hi,

I have a custom portlet for displaying a quiz question (multiple choice), on the right side of the page.
Now I have also created a Asset Publisher for this portlet. It displays the list of all the questions, on the left side of the page.
Now my requirement is when I click on a specific question on the asset publisher, the specific parameters (say - question id) be passed to the custom quiz portlet (on the same page).

I went through quite a few discussions, but most of them were related to web content display.
I am using liferay version 6.0.6.

Can anyone please help me.

Thanks in advance.
thumbnail
jelmer kuperus, modificado 12 Anos atrás.

RE: Link Asset Publisher to a custom portlet

Liferay Legend Postagens: 1191 Data de Entrada: 10/03/10 Postagens Recentes
Well you can do a number of things. You could change the portlet definition of assetpublisher in ext. Make it support a public render parameter that gets read by your other portlet. But that tighty couples your portlet to the assetpublisher. And changes in ext ar generally ill adviced. Instead in this case i would use liferay's clientside ipc. Send a javascript event from the asset publisher that gets picked up by your portlet who catches the even, constructs a portlet url in javascript and performs a redirect
Dipesh Sahu, modificado 12 Anos atrás.

RE: Link Asset Publisher to a custom portlet

New Member Postagens: 10 Data de Entrada: 24/07/11 Postagens Recentes
Hi Jelmer,

I was unable to find any message / forum / wiki in which there is any sample code for client side ipc for asset publisher.
So I tried doing a server side redirect... but was unsuccessful.

The following is my liferay-portlet.xml
The portlet is "abc-quiz" displays the quiz question. Parameter needs to be passed to this portlet.
The portlet "question-admin" is where asset publisher is present.


<liferay-portlet-app>

	<portlet>
		<portlet-name>abc-quiz</portlet-name>
		<icon>/icon.png</icon>
		<instanceable>true</instanceable>
		<header-portlet-css>/css/quiz_main.css</header-portlet-css>
		<footer-portlet-javascript>/js/quiz_main.js</footer-portlet-javascript>
	</portlet>

	<portlet>
		<portlet-name>question-admin</portlet-name>
		<icon>/icon.png</icon>
		<control-panel-entry-category>content</control-panel-entry-category>
		<control-panel-entry-weight>1.5</control-panel-entry-weight>
		<asset-renderer-factory>
			com.abc.portal.quiz.asset.QuestionAssetRendererFactory
		</asset-renderer-factory>		
		<instanceable>false</instanceable>
		<header-portlet-css>/css/question-admin.css</header-portlet-css>
		<header-portlet-javascript>/js/test.js</header-portlet-javascript>
	</portlet>
		.
		.
		.
</liferay-portlet-app>



The class QuestionAssetRenderer does the rendering, with the various getters and setters.



public class QuestionAssetRenderer extends BaseAssetRenderer 
{
.
.
.

	public String render(RenderRequest request, RenderResponse response, String template) throws Exception 
	{
        HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request);
		httpRequest = PortalUtil.getOriginalServletRequest(httpRequest);
		httpRequest.setAttribute("QUESTION_ID", _question.getQuestionId());
		PortletURL portletURL = PortletURLFactoryUtil.create(httpRequest ,"abcquiz_WAR_quizportlet_INSTANCE_c9mX", 20701 ,PortletRequest.RENDER_PHASE); 
		
        String path = portletURL.toString();
		return path ;

	}
}


I know I've hard-coded a few values for portletURL, but that's for the time being.


The control is still not going to the desired (2nd) portlet.
Can you please advise.

Thanks
thumbnail
Brian Scott Schupbach, modificado 11 Anos atrás.

RE: Link Asset Publisher to a custom portlet

Expert Postagens: 329 Data de Entrada: 23/10/08 Postagens Recentes
I'm using Liferay 6.1 GA2 and I get an error saying that the URL provided is not valid because it is not in the context root. I can't return a path back to my portlet with the custom asset. It only lets me return a path that is relative to the root.

To get around this will I need to create a EXT plugin? You'd think that if you have the ability to create custom asset types that you should be able to use .jsp files within your own portlet instead of needing to create a separate EXT plugin.

Can anyone verify?