Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Sơn Tuấn Nguyễn
Parameter handling with Action/Resource handler
August 18, 2012 10:57 PM
Answer

Sơn Tuấn Nguyễn

Rank: Junior Member

Posts: 37

Join Date: March 1, 2010

Recent Posts

I tried reading a xlsx then write it down to client side using <portlet:resourceURL> and ResourceRequest, ResourceResponse.

I've encountered a problem. Because serveResource(ResourceRequest req, ResourceResponse res) is differ from report(ActionRequest actionRequest, ActionResponse actionResponse), one is action handler, one is resource handler. I can't get parameters from actionRequest anymore. Those parameters are required to generate the excel report exactly.

For example: User inputs his name into input text field then I write that name in the pre-defined form in excel file, then give them the file. Reading and writing is ok but without the name input by user. Because there's no actionRequest in serveResource method.

OutputStream out = res.getPortletOutputStream();

res is ResourceResponse. This is how I get the output stream to write the file back to render phase. But in an action handler method, i dont have ResourceResponse, just ActionResponse, seem no way to get output stream.

If you still wonder about serveResource and Resource handler, here the article: http://www.liferay.com/web/raymond.auge/blog/-/blogs/801426
I followed the last sample.


Any help is appreciated. Thanks in advance.
Satheesh Ravi
RE: Parameter handling with Action/Resource handler
August 19, 2012 1:34 AM
Answer

Satheesh Ravi

Rank: Junior Member

Posts: 35

Join Date: November 24, 2011

Recent Posts

Why do u need action here? Everything can be done using serveResource itself. I mean the name parameter you pass can be passed using resourceRequest. You don't have to use action here.
Mayur Patel
RE: Parameter handling with Action/Resource handler
August 19, 2012 4:48 AM
Answer

Mayur Patel

Rank: Expert

Posts: 340

Join Date: November 17, 2010

Recent Posts

Exactly, Agree with Satheesh, you can use serverResource method only for this kind of problem
Sơn Tuấn Nguyễn
RE: Parameter handling with Action/Resource handler
August 20, 2012 2:10 AM
Answer

Sơn Tuấn Nguyễn

Rank: Junior Member

Posts: 37

Join Date: March 1, 2010

Recent Posts

Satheesh Ravi:
Why do u need action here? Everything can be done using serveResource itself. I mean the name parameter you pass can be passed using resourceRequest. You don't have to use action here.


You mean I can use resourceRequest.getParameter(String arg0) to get parameters like actionRequest.getParameter(String arg0)?
I will give it a shot to see how it work.

Thank you guys for the tips.
Sơn Tuấn Nguyễn
RE: Parameter handling with Action/Resource handler
August 20, 2012 2:25 AM
Answer

Sơn Tuấn Nguyễn

Rank: Junior Member

Posts: 37

Join Date: March 1, 2010

Recent Posts

I tested and we can only get parameter if we specify it like this, in the tag:

<portlet:resourceURL>
<portlet:param name="logo" value="true" />
</portlet:resourceURL>

For parameters in the form, where user can input values, resourceRequest doesn't get them at all.
That's the reason I need actionRequest.
Sơn Tuấn Nguyễn
RE: Parameter handling with Action/Resource handler
August 20, 2012 7:52 PM
Answer

Sơn Tuấn Nguyễn

Rank: Junior Member

Posts: 37

Join Date: March 1, 2010

Recent Posts

Still looking for a solution.
Andew Jardine
RE: Parameter handling with Action/Resource handler
August 20, 2012 8:19 PM
Answer

Andew Jardine

Rank: Regular Member

Posts: 238

Join Date: December 22, 2010

Recent Posts

As far as I know, resource requests don't receive parameters (whcih is why what you tried is not working). I had to do this once before on a different platform and if I remember correctly, I had to append the paramteres to the resource URL in order to have them available in the resource handler.
Sơn Tuấn Nguyễn
RE: Parameter handling with Action/Resource handler
August 20, 2012 8:53 PM
Answer

Sơn Tuấn Nguyễn

Rank: Junior Member

Posts: 37

Join Date: March 1, 2010

Recent Posts

Andew Jardine:
As far as I know, resource requests don't receive parameters (whcih is why what you tried is not working). I had to do this once before on a different platform and if I remember correctly, I had to append the paramteres to the resource URL in order to have them available in the resource handler.


Thank you Andrew, however, to generate the file I need user inputs. So I can't add parameter, as of course we dont know the value.

I think about solve the problem with action handler, but haven't found how to write the file back to client with action handler.
David H Nebinger
RE: Parameter handling with Action/Resource handler
August 20, 2012 9:40 PM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7004

Join Date: September 1, 2006

Recent Posts

Well, it's not quite elegant, but you do have a portlet session available via both of the request objects...

The action could populate the portlet session and the resource request can get the session values...

I am not crazy about this option as you still have to submit the form (to store the values) before you could submit the resource request.

The better method, IMHO, would be to use some fancy javascript code. Use JS to grab the form values and stuff them as parameters into the resource request manually. You're going to want to look at the actual rendered content of the resource tag to see how you have to manipulate it in Javascript, and you'll also have to deal w/ the portlet namespace when grabbing form field values...

And I'm not so crazy about this implementation either.

It's cases like this that make me glad I'm using Vaadin...
Sơn Tuấn Nguyễn
RE: Parameter handling with Action/Resource handler
August 20, 2012 11:50 PM
Answer

Sơn Tuấn Nguyễn

Rank: Junior Member

Posts: 37

Join Date: March 1, 2010

Recent Posts

David H Nebinger:
Well, it's not quite elegant, but you do have a portlet session available via both of the request objects...

The action could populate the portlet session and the resource request can get the session values...

I am not crazy about this option as you still have to submit the form (to store the values) before you could submit the resource request.

The better method, IMHO, would be to use some fancy javascript code. Use JS to grab the form values and stuff them as parameters into the resource request manually. You're going to want to look at the actual rendered content of the resource tag to see how you have to manipulate it in Javascript, and you'll also have to deal w/ the portlet namespace when grabbing form field values...

And I'm not so crazy about this implementation either.

It's cases like this that make me glad I'm using Vaadin...


Thanks David, you seems to be a ghost of the forum lol jk

I thought about js solution, not really a problem because i used to do something more crazy than that, but it's not beautiful you know. We always want to code in the best way, not just simply solve the problem.

I will give it a try with portlet session to see how.
Sơn Tuấn Nguyễn
RE: Parameter handling with Action/Resource handler
August 21, 2012 1:07 AM
Answer

Sơn Tuấn Nguyễn

Rank: Junior Member

Posts: 37

Join Date: March 1, 2010

Recent Posts

I finally found out how to handle it. Thanks David for the tip about Portlet Session.

I submit form to action handler, get parameters then store in session. Render phase I make resource request by js. Then just simply get parameters from session.

Once again thank you guys for support. Great community.