Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Sơn Tuấn Nguyễn
Parameter handling with Action/Resource handler
18. August 2012 22:57
Antwort

Sơn Tuấn Nguyễn

Rang: Junior Member

Nachrichten: 37

Eintrittsdatum: 1. März 2010

Neue Beiträge

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
19. August 2012 01:34
Antwort

Satheesh Ravi

Rang: Junior Member

Nachrichten: 35

Eintrittsdatum: 24. November 2011

Neue Beiträge

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
19. August 2012 04:48
Antwort

Mayur Patel

Rang: Expert

Nachrichten: 341

Eintrittsdatum: 17. November 2010

Neue Beiträge

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
20. August 2012 02:10
Antwort

Sơn Tuấn Nguyễn

Rang: Junior Member

Nachrichten: 37

Eintrittsdatum: 1. März 2010

Neue Beiträge

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
20. August 2012 02:25
Antwort

Sơn Tuấn Nguyễn

Rang: Junior Member

Nachrichten: 37

Eintrittsdatum: 1. März 2010

Neue Beiträge

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
20. August 2012 19:52
Antwort

Sơn Tuấn Nguyễn

Rang: Junior Member

Nachrichten: 37

Eintrittsdatum: 1. März 2010

Neue Beiträge

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

Andew Jardine

Rang: Expert

Nachrichten: 289

Eintrittsdatum: 22. Dezember 2010

Neue Beiträge

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
20. August 2012 20:53
Antwort

Sơn Tuấn Nguyễn

Rang: Junior Member

Nachrichten: 37

Eintrittsdatum: 1. März 2010

Neue Beiträge

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
20. August 2012 21:40
Antwort

David H Nebinger

Rang: Liferay Legend

Nachrichten: 7252

Eintrittsdatum: 1. September 2006

Neue Beiträge

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
20. August 2012 23:50
Antwort

Sơn Tuấn Nguyễn

Rang: Junior Member

Nachrichten: 37

Eintrittsdatum: 1. März 2010

Neue Beiträge

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
21. August 2012 01:07
Antwort

Sơn Tuấn Nguyễn

Rang: Junior Member

Nachrichten: 37

Eintrittsdatum: 1. März 2010

Neue Beiträge

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.