Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Jesse Paria
Load page via ajax
December 21, 2011 5:28 PM
Answer

Jesse Paria

Rank: Junior Member

Posts: 69

Join Date: March 4, 2011

Recent Posts

I would like to load the portlets that are on a page via ajax into another page.

I understand how to do this via jQuery ajax.

What I don't know is how to get the URL that will just load the portlets on that page and not the theme elements that are applied to that page.

Thanks
David H Nebinger
RE: Load page via ajax
December 21, 2011 6:44 PM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 8555

Join Date: September 1, 2006

Recent Posts

I'm not sure what you're really asking for here... And I can't really tell what your background may be, either, so I'm going to take a couple of swings at the ball and hopefully hit one...

From the perspective of you know jQuery and how to move items from one page to another, I'll assume you're a smart javascript person and you're wanting to grab the DOM elements that constitute a portlet for relocating them on another page (why, I don't know). In the browser all of the portlet content can be found within a DIV section that has a CSS class of "portlet-boundary". Now this div is the container for the whole portlet content (title bar, any icons, etc.). Now if you're just looking for the body portion of the portlet, then you want a DIV of CSS class "portlet-body".

Now, "load the portlets that are on a page via ajax into another page", is open to a number of different interpretations. Are you saying that "Via an ajax call to the portal I want a portlet that is currently placed on page A to also be placed on page B", then I'd point you to the scripting behind the "Add -> More" menu off of the dock. There portlets can be added to the page and this is primarily done via ajax.

If the emphasis is supposed to be on "the portlets that are on a page via ajax", and you want to load them on another page, well then you might be under some misconception about how the portal is actually putting the portlet on a page. It's not done via ajax, the incoming http request is handled by the portal which, in a series of steps and phases, will result in each portlet rendering a snippet of HTML that represents the body that the portal aggregates into an http response for the browser to render.

This one's an even bigger mystery: "I don't know how to get the URL that will just load the portlets on that page and not the theme elements" There is no URL for doing this. The portal aggregates the content via the standard http request/response cycle, it's not like the portal is rendering a simple page that, when rendered in the browser, invokes javascript to tell the portlets to render the content and display in the browser individually. A single incoming http request to the portal results in each portlet generating an HTML snippet that the portal aggregates into the single outgoing http response.

I know, I said that before, but based upon the many possible interpretations of what you're asking, it seemed like that statement should be emphasized a second time...
Jesse Paria
RE: Load page via ajax
December 21, 2011 8:04 PM
Answer

Jesse Paria

Rank: Junior Member

Posts: 69

Join Date: March 4, 2011

Recent Posts

Well firstly thanks for replying to my post.

I am simply asking for a way to pull the content of a page separate from the template. I am really surprised that Liferay does not have this ability as it strives to separate content from presentation.

I realize that through jQuery I could pull the content via a url and then actually only load the dom element that I need, but the problem with this is that it loads the entire page into the browser dom and then pulls the the content specified therefore loading tons of extra images and content that is not needed (i.e. the template).

From what I understand of Liferay is that a layout (page) stores the portlet and instance ids for that page. I am surprised I am unable to just request this from the server.

Perhaps I need to provide a better idea of what I am trying to achieve.

Instead of having one page with 10 portlets on it, I was thinking that perhaps I could create children pages with perhaps 2 portlets each and then load those pages via ajax onto the parent page to minimize the load time of that page. So I was going to iterate through the children of that page and load the contents via Ajax.

This make sense?

Thanks
David H Nebinger
RE: Load page via ajax
December 21, 2011 8:32 PM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 8555

Join Date: September 1, 2006

Recent Posts

Okay, that makes sense, but it's really not going to be practical.

If you have page loading issues, I'd start by analyzing the portlets themselves. We typically try to do portlet initialization at portlet creation time (when the portal creates our instance, we use Spring's InitializingBean interface to instantiate whatever static lists are used by the portlet), and within the portlet itself try to do things as lazily as possible (only pull data when it's needed, etc).

You should also ensure that your portlets are only rendering content in the render phase, they should not be doing database queries, web service calls, or any activity really. All of those activities should be in the action phase.

I think if you analyze your portal page load/rendering you'll find that the bulk of the time is in the portlets themselves and that they're doing things in the render phase that they really shouldn't be doing.

Trying to come up w/ some hokey javascript/jquery solution to a problem that is not really the portal's problem is just going to hide the problem, not solve it...
Jesse Paria
RE: Load page via ajax
December 21, 2011 10:36 PM
Answer

Jesse Paria

Rank: Junior Member

Posts: 69

Join Date: March 4, 2011

Recent Posts

I am only in wireframe phase of the site so I am not really sure I will have load issues. I just figured that if I could load the portlets that aren't needed immediately via ajax after page load then it would minimize wait time on the initial page load.

I find it strange that you think loading content via ajax is hokey. This is a very standard practice.

Thanks for the tips on optimizing the portlets. I am the theme developer and therefore I have very little to do with the portlets that will be deployed.
David H Nebinger
RE: Load page via ajax
December 22, 2011 5:25 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 8555

Join Date: September 1, 2006

Recent Posts

No, I think I misrepresented myself...

I believe fully that portlets should use as much ajax as possible as the typical portlet request/response process can be quite heavy. Right now we're working in Vaadin which makes heavy use of AJAX (via the GWT) to do all communications between client & servlet.

What I think is hokey is trying to build a complicated js engine to load portlet content in separate windows and try to move it onto the main browser window. Issues w/ keeping the placeholders on the main page (so user knows where content will be), juggling extra pages used to actually load the content, managing all of their states, copying the content and allowing for recovery from collisions due to id reuse, translating the scripts, events, dom, etc from the source page to the target page, dealing w/ user interaction on the main page while the window is still loading...

That's just a quick list of issues I can think of that you'd have to deal with, and I'm sure that it is quite incomplete.

And only being at wireframe stage, you're already looking to build this hokey solution w/o even knowing if it is a problem that you'll actually encounter...
Jesse Paria
RE: Load page via ajax
December 22, 2011 9:56 AM
Answer

Jesse Paria

Rank: Junior Member

Posts: 69

Join Date: March 4, 2011

Recent Posts

Yes the issues you state may be an issue, however I wasn't looking at building something quite as complex or as "hokey" as you state.

I know looking at new and out-of-the-box way of doing things may seem strange to you but you don't have to degrade someone just for contemplating if an idea would work by calling their idea hokey.

As I stated earlier, loading content via ajax into elements in the dom is a very common practice outside of Liferay and you will see enterprise level solutions do this all the time to reduce the load time of a page. In fact, their are entire js frameworks devoted to doing this.

Normally everyone on this forum is very positive and helpful and I am grateful for that.
David H Nebinger
RE: Load page via ajax
December 22, 2011 10:09 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 8555

Join Date: September 1, 2006

Recent Posts

My intent was not to degrade you and must apologize if I did.

AJAX loading of content at the portlet level is supported by some of the portlet frameworks, but not all of them.

The point that I was trying to make (I guess a little poorly) is that from the portlet development standpoint you should encourage your developers to leverage a framework that supports AJAX loading of the portlet-specific content. But from the overall portal page perspective it will be difficult if not impossible to implement or enforce AJAX loading of the total portlet content.

I should point out that any implementation that would try such a thing would have to address all of the issues I mentioned or would probably end in failure.
Hitoshi Ozawa
RE: Load page via ajax
December 22, 2011 6:41 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7952

Join Date: March 23, 2010

Recent Posts

Instead of using ajax to load other pages, I think there was some other user using iframe to show contents from other pages.
Jesse Paria
RE: Load page via ajax
January 5, 2012 1:15 PM
Answer

Jesse Paria

Rank: Junior Member

Posts: 69

Join Date: March 4, 2011

Recent Posts

Thanks for all your help. Very helpful.