Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
Dipesh Sahu
Link Asset Publisher to a custom portlet
19 dicembre 2011 12.19

Dipesh Sahu

Punteggio: New Member

Messaggi: 10

Data di Iscrizione: 23 luglio 2011

Messaggi recenti


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.
Jelmer Kuperus
RE: Link Asset Publisher to a custom portlet
19 dicembre 2011 23.50

Jelmer Kuperus

Punteggio: Liferay Legend

Messaggi: 1192

Data di Iscrizione: 10 marzo 2010

Messaggi recenti

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
RE: Link Asset Publisher to a custom portlet
20 dicembre 2011 13.21

Dipesh Sahu

Punteggio: New Member

Messaggi: 10

Data di Iscrizione: 23 luglio 2011

Messaggi recenti

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.

 3    <portlet>
 4        <portlet-name>abc-quiz</portlet-name>
 5        <icon>/icon.png</icon>
 6        <instanceable>true</instanceable>
 7        <header-portlet-css>/css/quiz_main.css</header-portlet-css>
 8        <footer-portlet-javascript>/js/quiz_main.js</footer-portlet-javascript>
 9    </portlet>
11    <portlet>
12        <portlet-name>question-admin</portlet-name>
13        <icon>/icon.png</icon>
14        <control-panel-entry-category>content</control-panel-entry-category>
15        <control-panel-entry-weight>1.5</control-panel-entry-weight>
16        <asset-renderer-factory>
18        </asset-renderer-factory>       
19        <instanceable>false</instanceable>
20        <header-portlet-css>/css/question-admin.css</header-portlet-css>
21        <header-portlet-javascript>/js/test.js</header-portlet-javascript>
22    </portlet>
23        .
24        .
25        .

The class QuestionAssetRenderer does the rendering, with the various getters and setters.
 4public class QuestionAssetRenderer extends BaseAssetRenderer
10    public String render(RenderRequest request, RenderResponse response, String template) throws Exception
11    {
12        HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request);
13        httpRequest = PortalUtil.getOriginalServletRequest(httpRequest);
14        httpRequest.setAttribute("QUESTION_ID", _question.getQuestionId());
15        PortletURL portletURL = PortletURLFactoryUtil.create(httpRequest ,"abcquiz_WAR_quizportlet_INSTANCE_c9mX", 20701 ,PortletRequest.RENDER_PHASE);
17        String path = portletURL.toString();
18        return path ;
20    }

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.

Brian Scott Schupbach
RE: Link Asset Publisher to a custom portlet
28 febbraio 2013 8.41

Brian Scott Schupbach

Punteggio: Expert

Messaggi: 331

Data di Iscrizione: 23 ottobre 2008

Messaggi recenti

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?