Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Derek Li
Portlet is loaded twice on one page
April 28, 2011 7:30 PM
Answer

Derek Li

Rank: New Member

Posts: 14

Join Date: April 27, 2011

Recent Posts

Hi all,

I'm currently facing a problem that the portlet I'm developing is loaded twice if the page is refreshed. My portlet is developed using ExtJS, which generates a grid panel after the portlet is loaded. But unfortunately, the portlet is loaded twice, which makes the javascript code that generates the grid panel execute twice. Then I'm seeing two grid panels on the page in the same portlet area. But if I refresh the page again, the duplicate panel disappears.

Here is how I find my portlet is loaded twice. I open the console panel in fire bug and find there are two items of my portlet. The response of these two items are the same. But I can't see any other portlet that has the same problem.

Does anyone have any idea about this issue? Thanks.
Hitoshi Ozawa
RE: Portlet is loaded twice on one page
April 29, 2011 6:34 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

Is this happening on all web browsers - e.g. IE, Chrome, Firefox?

Unfortunately, I haven't experienced this with any web browser.
Olaf Kock
RE: Portlet is loaded twice on one page
April 29, 2011 7:22 AM
Answer

Olaf Kock

LIFERAY STAFF

Rank: Liferay Legend

Posts: 3474

Join Date: September 23, 2008

Recent Posts

Do the two items have different IDs? e.g. take a look at the DOM code and identify portlet boundaries. If you have it once on the page (e.g. one <div id="p_p_id_YOUR-PORTLET-NAME_INSTANCE_Aen1_"> with the javascript twice in it, then (most likely) your portlet generates the javascript blocks wrong, e.g. twice. (you won't have the ...INSTANCE_xxxx part of the id when you don't have an instanceable portlet)
Hitoshi Ozawa
RE: Portlet is loaded twice on one page
May 1, 2011 4:06 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

But if I refresh the page again, the duplicate panel disappears.


If the portlet is generating new ids on each refresh, I think there would still be 3 panels after the second refresh.
I've sometimes seen differences between the browsers.

Well, the easiest way to solve this problem is for Derek to attach his portlet here. emoticon
Tanweer .
RE: Portlet is loaded twice on one page
May 1, 2011 7:58 AM
Answer

Tanweer .

Rank: Expert

Posts: 319

Join Date: March 11, 2010

Recent Posts

Derek,

Are you somewhere using a Ajax call or window.location in this jsp ?
Derek Li
RE: Portlet is loaded twice on one page
May 2, 2011 7:21 PM
Answer

Derek Li

Rank: New Member

Posts: 14

Join Date: April 27, 2011

Recent Posts

Hitoshi Ozawa:
Is this happening on all web browsers - e.g. IE, Chrome, Firefox?

Unfortunately, I haven't experienced this with any web browser.



This only happens on Firefox.
Derek Li
RE: Portlet is loaded twice on one page
May 2, 2011 7:25 PM
Answer

Derek Li

Rank: New Member

Posts: 14

Join Date: April 27, 2011

Recent Posts

Olaf Kock:
Do the two items have different IDs? e.g. take a look at the DOM code and identify portlet boundaries. If you have it once on the page (e.g. one <div id="p_p_id_YOUR-PORTLET-NAME_INSTANCE_Aen1_"> with the javascript twice in it, then (most likely) your portlet generates the javascript blocks wrong, e.g. twice. (you won't have the ...INSTANCE_xxxx part of the id when you don't have an instanceable portlet)


They have exactly the same ID. That explains why the two grid panels are generated in the same portlet boundaries.
Hitoshi Ozawa
RE: Portlet is loaded twice on one page
May 2, 2011 8:00 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

This only happens on Firefox.


Thought so. This may be a problem with AlloyUI. Different web browser have different rendering technique. It seems rendering is being called twice on Firefox in your situation. I've seen this happen when there is an unintended recursive call.

It may a problem with AlloyAU, with your code, or Firefox but I can't comment any further. You'll just have to trace where the second call is being made.
Derek Li
RE: Portlet is loaded twice on one page
May 2, 2011 8:05 PM
Answer

Derek Li

Rank: New Member

Posts: 14

Join Date: April 27, 2011

Recent Posts

Tanweer Ahmed Ansari:
Derek,

Are you somewhere using a Ajax call or window.location in this jsp ?


I do use Ajax call, but that only triggers after the portlet finishes loading.
Derek Li
RE: Portlet is loaded twice on one page
May 2, 2011 8:13 PM
Answer

Derek Li

Rank: New Member

Posts: 14

Join Date: April 27, 2011

Recent Posts

Hitoshi Ozawa:
This only happens on Firefox.


Thought so. This may be a problem with AlloyUI. Different web browser have different rendering technique. It seems rendering is being called twice on Firefox in your situation. I've seen this happen when there is an unintended recursive call.

It may a problem with AlloyAU, with your code, or Firefox but I can't comment any further. You'll just have to trace where the second call is being made.


I have made some changes to the file webapps\ROOT\html\portal\render_portlet.jsp. When a porltet is loaded to the page the following code is executed:

Liferay.Portlet.onLoad(
{
canEditTitle: <%= showConfigurationIcon %>,
columnPos: <%= columnPos %>,
isStatic: '<%= staticVar %>',
namespacedId: 'p_p_id<%= HtmlUtil.escapeJS(renderResponseImpl.getNamespace()) %>',
portletId: '<%= HtmlUtil.escapeJS(portletDisplay.getId()) %>',
refreshURL: '<%= HtmlUtil.escapeJS(PortletURLUtil.getRefreshURL(request, themeDisplay)) %>'
}
);

So, I just leave a log when the above code is run by adding:

console.log('<%= HtmlUtil.escapeJS(PortletURLUtil.getRefreshURL(request, themeDisplay)) %>');

Then I am able to know what is happening when a portlet is loaded. But unfortunately, the portlet that has issue only loaded once here. I have no idea where the second load happens. And it seems that the load doesn't happen immediately after the above code is run, because I find that the request of loading portlet doesn't come right after the log. Any further ideas?
Derek Li
RE: Portlet is loaded twice on one page
May 2, 2011 8:16 PM
Answer

Derek Li

Rank: New Member

Posts: 14

Join Date: April 27, 2011

Recent Posts

Hitoshi Ozawa:
But if I refresh the page again, the duplicate panel disappears.


If the portlet is generating new ids on each refresh, I think there would still be 3 panels after the second refresh.
I've sometimes seen differences between the browsers.

Well, the easiest way to solve this problem is for Derek to attach his portlet here. emoticon


The weird thing is the duplicate panel only comes out on the first refresh after I open the browser, it disappears on the second refresh, and after that it never comes out again no matter how many times I refresh the page unless I restart the browser.
Hitoshi Ozawa
RE: Portlet is loaded twice on one page
May 2, 2011 9:20 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

It's not the portlet coding. Use Firebug to trace when the second div is being created. There's usally a workaround to get around some particularity of Firefox.

Instead of trying to prevent the second div from being created, it may just be easier to execute a reload on the portlet to make the second one disappear.
Sharana Basavaraj Ballari
RE: Portlet is loaded twice on one page
May 3, 2011 4:19 AM
Answer

Sharana Basavaraj Ballari

Rank: Regular Member

Posts: 139

Join Date: September 9, 2007

Recent Posts

Hi There,

I think it is just because you have deployed the portlet too many times with different name or Id, the old instance is still there in the Liferay Layout typeSettings I belive.

The best thing and quick solution that you can have is,

Delete the current Page, create it again and add the portlet. by doing this typeSettings will get newly created and you may not face the duplication issue.

HTH,
Sharan
Konstantin Chudinov
RE: Portlet is loaded twice on one page
December 7, 2013 3:59 AM
Answer

Konstantin Chudinov

Rank: Junior Member

Posts: 43

Join Date: April 23, 2013

Recent Posts

I have the same problem! How do you fix it?
I also use ExtJS (charts) on portlet page. Chart prints twice
Andrew Jardine
RE: Portlet is loaded twice on one page
December 8, 2013 8:21 PM
Answer

Andrew Jardine

Community Moderator

Rank: Liferay Legend

Posts: 1062

Join Date: December 22, 2010

Recent Posts

Hey Guys,

I was suffering the same issue and figured out that they were the result 404's. I found a fix after crawling through the MainServlet -- though i still don't understand the solution. The solution I used was to add the following to my init.jsp in each of my portlets --

1
2        PortletURL currentURLObj = PortletURLUtil.getCurrent(liferayPortletRequest, liferayPortletResponse);
3    String currentURL = currentURLObj.toString();


-- as soon as I used this code and redeployed I no longer saw my render methods running multiple times, regardless of the missing resources.
Anil T
RE: Portlet is loaded twice on one page
February 5, 2014 8:42 PM
Answer

Anil T

Rank: Expert

Posts: 294

Join Date: January 14, 2012

Recent Posts

Hi Andew,

I have used your above code in my portlet but still its calling render method twice. Have you found any solution ? Please share with us .

Thanks,
Anil
Zsolt - Jácint Balogh
RE: Portlet is loaded twice on one page
December 3, 2015 2:10 AM
Answer

Zsolt - Jácint Balogh

Rank: Junior Member

Posts: 91

Join Date: October 9, 2013

Recent Posts

Hi all,

I had the same problem with Liferay 6.2. In my case the problem was that I used the # in the SRC tag of an image.

1<img src="#" />
this one refreshed the page twice and the action method was called twice.

1<img src="/documents/10658/21815/cfd8c9df-9a54-4df7-a905-6e2bbc34b5cf/bf06cf6a-38d4-4875-918d-08fed62b9745" />
With this one worked.

I spend 2 days from my life finding this.
Somebody can explain me why is this?

Regards,
Zsolt
Andrew Jardine
RE: Portlet is loaded twice on one page
December 7, 2015 9:26 AM
Answer

Andrew Jardine

Community Moderator

Rank: Liferay Legend

Posts: 1062

Join Date: December 22, 2010

Recent Posts

In the end for me (with 6.1 GA2) it was the same issue (if memory serves). We found that broken resource links (in certain situations) were causing portlets on the page to load more than once. Interestingly though, the currentURL code I referenced in my other post also seemed to resolved the problem for us on certain pages.
Olaf Kock
RE: Portlet is loaded twice on one page
January 4, 2016 1:07 AM
Answer

Olaf Kock

LIFERAY STAFF

Rank: Liferay Legend

Posts: 3474

Join Date: September 23, 2008

Recent Posts

Zsolt - Jácint Balogh:
Hi all,

I had the same problem with Liferay 6.2. In my case the problem was that I used the # in the SRC tag of an image.

1<img src="#" />
this one refreshed the page twice and the action method was called twice.


Of course it did. # is an anchor in the current page - in other words the URL that you state as the location of your image is the same URL that you load the current page as. The resulting duplicate HTML code for the current page is html, not jpg/png/gif or similar, thus the browser does not display it as image. But as you state that the browser can find an image under the current URL, it will happily request the image before deciding not being able to show it. And that's what you observe - server side - as duplicate page request.