留言板

Can not retrieve request attributes (trunk)

thumbnail
Leo Pratlong,修改在12 年前。

Can not retrieve request attributes (trunk)

Expert 帖子: 363 加入日期: 10-7-6 最近的帖子
Hi,

I am redefining the behaviour of the DocumentLibrary. I adapt a code I made for 6.0.6 to the trunk of Liferay CE.
There is a part on a plugin EXT and a part on a Hook.
On the Ext, I redefine com.liferay.portlet.documentlibrary.action.ViewAction (on the "render" method):


final List<dlfileentry> fileEntries = (List<dlfileentry>) DLFileEntryLocalServiceUtil.dynamicQuery(query, 0, fileEntriesDisplayNumber);
// the list is not empty...
renderRequest.setAttribute(WebKeys.FILE_ENTRIES_CUSTOM_LIST, fileEntries);</dlfileentry></dlfileentry>


No problem with this code. It works.

But, on the Hook, I do not succeed to retrieve this file.
I redefine html/portlet/document_library/view_entries.jsp:

     if (isLastDocuments || isTopDownloads || isLastUpdates) {
        
        results = (List<dlfileentry>) request.getAttribute(WebKeys.FILE_ENTRIES_CUSTOM_LIST);
        // Results is null... That's not normal!
        if (results != null) {
            total = results.size();
        }
     }</dlfileentry>


I do not understand. In other JSP, I see exactly the same process and it works. Is there a new way to manage that with Liferay 6.1?
I work with trunk, revision 1caa998bcd9627f64413cc4f26a206e388aa750e .

Thanks!
thumbnail
Leo Pratlong,修改在12 年前。

RE: Can not retrieve request attributes (trunk)

Expert 帖子: 363 加入日期: 10-7-6 最近的帖子
Looks like the kind of lazy loading on the DocumentLibrary is the cause of the problem:
the JSP is processed many times. And at the last process, renderRequest is null.
HttpServletRequest is well initialized but not the RenderRequest. And I think this explain the behaviour I describe earlier.

I don't know if it's a normal behaviour or a bug. I tried to get my values through the PortletSession, but without the renderRequest, I'm not able to get it on my JSP.
So, I'm totally lost with this. I'll be grateful to any help.


Edit:
Hmmm... view_resources.jsp is called just before the view_entries.jsp is processed. I'll share the solution if I find it soon.

Edit Edit:
Ok. I think I got it: resourceRequest instead of renderRequest...

Final edit and solution:
On Liferay 6.1 (the trunk now), DocumentLibrary displays resources with a lazy loading, allowing to show some part of the portlet while all requested resources are loading.
When these resources are ready (I think, maybe I say wrong), a dispatcher calls the JSPs. The ViewAction of the Document Library initializes the dispatcher here:
PortletRequestDispatcher portletRequestDispatcher =
			portletContext.getRequestDispatcher(
				"/html/portlet/document_library/view_resources.jsp");

		portletRequestDispatcher.include(resourceRequest, resourceResponse);


We can see that resourceRequest and resourceResponse are included. They play the role of renderRequest and renderResponse. That's why, on the JSP, renderRequest is null and not resourceRequest.
But, this solution works only for a bypass with the PortletSession. I still not succeed to retrieve my value on the request attributes.
Maybe I have totally wrong emoticon.