Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Salvatore Piccione
Behaviuor of Multiple Portlet Instances in the same page
February 3, 2011 9:16 AM
Answer

Salvatore Piccione

Rank: New Member

Posts: 6

Join Date: January 25, 2011

Recent Posts

Hello everybody,

I developed a simple JSR-286 portlet in order to test how Liferay (6.0.5) handles multiple instances of the same portlet in the same page. This portlet supported VIEW, EDIT and HELP modes (I subclassed javax.portlet.GenericPortlet in order to implement the mode processing logic - just a simple redirect to specific JSP pages which provides the HTML fragment to be rendered). I created a portal page and put some instances of this portlet on that page.
I noticed that every status change of a portlet instance caused the reload of the content of the other portlets (obviousliy according to their current mode).
I am new to portlet and Liferay and, maybe, my question could be stupid. I would like to know if there is a way to avoid that a change in the mode of a portlet instance causes the other instances of the same portlet (placed in the same page) to be reloaded.

Any suggestion is appreciated.

Regards,

Salvatore
Jelmer Kuperus
RE: Behaviuor of Multiple Portlet Instances in the same page
February 3, 2011 1:29 PM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

You should make your portlet instanceable in that case. There is more about that here

http://www.liferay.com/documentation/liferay-portal/6.0/development/-/ai/anatomy-of-a-portlet
Salvatore Piccione
RE: Behaviuor of Multiple Portlet Instances in the same page
February 4, 2011 1:01 AM
Answer

Salvatore Piccione

Rank: New Member

Posts: 6

Join Date: January 25, 2011

Recent Posts

Thanks for your reply, Jelmer. I forgot to write in the previous post that my simple portlet was already defined as instanceable (I put <instanceable>true</instanceable> in my liferay-portlet.xml). That strange behaviour occurs for multiple instances of the same portlet (defined as instanceable) and placed in the same page.
Oliver Bayer
RE: Behaviuor of Multiple Portlet Instances in the same page
February 4, 2011 1:30 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 875

Join Date: February 18, 2009

Recent Posts

Hi Salvatore,

setting the instancable flag as Jelmer said should work.

But if it doesn't as in your case you can use firebug to check if each portlet on your page has a different instance-id. If all have the same id then it's normal that all of them change their state at the same time. That means your changes aren't reflected. If the ids are different you have to do more debugging...

HTH Oli
Salvatore Piccione
RE: Behaviuor of Multiple Portlet Instances in the same page
February 4, 2011 7:43 AM
Answer

Salvatore Piccione

Rank: New Member

Posts: 6

Join Date: January 25, 2011

Recent Posts

Thanks for your suggestions, Oliver.
I succefully checked that Liferay assign a unique ID to each instance of the portlet.
I also noticed that when a portlet instance changed its mode all the portal page was reloaded: this caused all other portlet instances to be reloaded. This happened because the URL of the portal page changes in order to reflect the portlet instance mode change.
I would like to know if the whole portal page is loaded because of the way I handle portlet mode. Below you can find the code of the Portlet class I defined:
 1public class TestMultiplePortlet extends GenericPortlet {
 2
 3    public void doView(RenderRequest request, RenderResponse response)
 4            throws PortletException, IOException {
 5        System.out.println("VIEW " + request.getWindowID());
 6        response.setContentType("text/html");
 7       
 8        PortletRequestDispatcher dispatcher =
 9            getPortletContext().getRequestDispatcher("/WEB-INF/jsp/TestMultiplePortlet_view.jsp");
10        dispatcher.include(request, response);
11       
12    }
13
14
15    public void doEdit(RenderRequest request, RenderResponse response)
16            throws PortletException, IOException {
17        System.out.println("EDIT " + request.getWindowID());
18        response.setContentType("text/html");
19       
20        PortletRequestDispatcher dispatcher =
21            getPortletContext().getRequestDispatcher("/WEB-INF/jsp/TestMultiplePortlet_edit.jsp");
22        dispatcher.include(request, response);
23       
24    }
25
26    public void doHelp(RenderRequest request, RenderResponse response)
27            throws PortletException, IOException {
28        System.out.println("HELP " + request.getWindowID());
29        response.setContentType("text/html");
30       
31        PortletRequestDispatcher dispatcher =
32            getPortletContext().getRequestDispatcher("/WEB-INF/jsp/TestMultiplePortlet_help.jsp");
33        dispatcher.include(request, response);
34       
35    }
36}

As you can see, every change in portlet mode causes a dispatching to a specific JSP that provides some HTML tags. Could this dispatching be the cause of the reload of the entire page? In general, is this a "normal" behaviour?
I enclosed a ZIP archive (testMultiplePortlets.zip) which contains the Eclipse Helios Project I used to define the portlet.
Attachments: testMultiplePortlets.zip (7.6k)
Sachin Hande
RE: Behaviuor of Multiple Portlet Instances in the same page
February 15, 2012 1:58 AM
Answer

Sachin Hande

Rank: New Member

Posts: 1

Join Date: February 15, 2012

Recent Posts

Hi,

I am also having the same issue. I have two instances of the same portlet on the same page. Changes done to one portlet are getting refelected in the another portlet.

How can we keep the two portlets independent.?

Thanks,
Sachin
Raja Nagendra Kumar
RE: Behaviuor of Multiple Portlet Instances in the same page
February 15, 2012 2:06 AM
Answer

Raja Nagendra Kumar

Rank: Expert

Posts: 484

Join Date: March 1, 2006

Recent Posts

Check your code.. may be you are using some global data.. either from DB or global variables

In the code all of them will use same JSP page /WEB-INF/jsp/TestMultiplePortlet_view.jsp

If the JSP page does not a logic specific to each preferences of the portlet.. then all of them would see the same content..

Make sure all the view is generated based on portlet preferences, which can be customised...

e.g let the jsp render all the portlet preferences, then you would see all of them would be displaying its own preferences as customized in edit mode.

By default all the portlets are insatiable.. so need not play with this parameter..

Regards,
Raja Nagendra Kumar,
C.T.O
www.tejasoft.com
Roberto Javier
RE: Behaviuor of Multiple Portlet Instances in the same page
March 15, 2012 1:20 PM
Answer

Roberto Javier

Rank: New Member

Posts: 5

Join Date: March 1, 2012

Recent Posts

Hi Salvatore, I have the same problem, could you solve it?
Salvatore Piccione
RE: Behaviuor of Multiple Portlet Instances in the same page
March 16, 2012 1:53 AM
Answer

Salvatore Piccione

Rank: New Member

Posts: 6

Join Date: January 25, 2011

Recent Posts

Hello Roberto,

unfortunately I haven't found a way to solve that issue. Raja pointed out that the portlet should be "customized" in some way and I was using already the portlet preferences to configure each portlet instance. I guess the problem is due to the HTTP GET that is made in order to change the status of a portlet (e.g. from VIEW MODE to EDIT MODE and viceversa): the target URL is different from the URL of the page thats send the HTTP GET corresponding to the mode change of a portlet instance.

Regards,

Salvatore
Roberto Javier
RE: Behaviuor of Multiple Portlet Instances in the same page
March 16, 2012 5:52 AM
Answer

Roberto Javier

Rank: New Member

Posts: 5

Join Date: March 1, 2012

Recent Posts

Thanks Salvatore,
I have 2 instances of the same portlet, I do something like this in the VIEW.JSP:

<c:set var="portletNameSpace"><portlet:namespace/></c:set>

<portlet:renderURL var="formAction">
<portlet:param name="action" value="uploadFileForm"/>
</portlet:renderURL>

<form:form id="${portletNameSpace}Form" name="${portletNameSpace}Form" action="${formAction}" commandName="uploadForm" method="post" enctype="multipart/form-data">
<form:input style="width:100%;" type="file" path="file" />
<input type="submit" value="SELECT FILE" ><br>
</form:form>


when I submit to the portlet instance 1, runs good, but later, when I submit to the instance 2, to arrive Controller preferences instance 1, and return 1 also refreshes the body. As seen in the jsp, everything is associated with the instance name, so it should work.
Do not know what else can be done.
Regards,

Roberto