Foren

Link Asset Publisher to a custom portlet

Dipesh Sahu, geändert vor 12 Jahren.

Link Asset Publisher to a custom portlet

New Member Beiträge: 10 Beitrittsdatum: 24.07.11 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: Link Asset Publisher to a custom portlet

Liferay Legend Beiträge: 1191 Beitrittsdatum: 10.03.10 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: Link Asset Publisher to a custom portlet

New Member Beiträge: 10 Beitrittsdatum: 24.07.11 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: Link Asset Publisher to a custom portlet

Expert Beiträge: 329 Beitrittsdatum: 23.10.08 Neueste Beiträge
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?