Forums de discussion

Parameter handling with Action/Resource handler

thumbnail
Sơn Tuấn Nguyễn, modifié il y a 11 années.

Parameter handling with Action/Resource handler

Junior Member Publications: 37 Date d'inscription: 02/03/10 Publications récentes
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, modifié il y a 11 années.

RE: Parameter handling with Action/Resource handler

Junior Member Publications: 35 Date d'inscription: 25/11/11 Publications récentes
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.
thumbnail
Mayur Patel, modifié il y a 11 années.

RE: Parameter handling with Action/Resource handler

Expert Publications: 358 Date d'inscription: 17/11/10 Publications récentes
Exactly, Agree with Satheesh, you can use serverResource method only for this kind of problem
thumbnail
Sơn Tuấn Nguyễn, modifié il y a 11 années.

RE: Parameter handling with Action/Resource handler

Junior Member Publications: 37 Date d'inscription: 02/03/10 Publications récentes
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.
thumbnail
Sơn Tuấn Nguyễn, modifié il y a 11 années.

RE: Parameter handling with Action/Resource handler

Junior Member Publications: 37 Date d'inscription: 02/03/10 Publications récentes
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.
thumbnail
Sơn Tuấn Nguyễn, modifié il y a 11 années.

RE: Parameter handling with Action/Resource handler

Junior Member Publications: 37 Date d'inscription: 02/03/10 Publications récentes
Still looking for a solution.
thumbnail
Andew Jardine, modifié il y a 11 années.

RE: Parameter handling with Action/Resource handler

Liferay Legend Publications: 2416 Date d'inscription: 22/12/10 Publications récentes
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.
thumbnail
Sơn Tuấn Nguyễn, modifié il y a 11 années.

RE: Parameter handling with Action/Resource handler

Junior Member Publications: 37 Date d'inscription: 02/03/10 Publications récentes
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.
thumbnail
David H Nebinger, modifié il y a 11 années.

RE: Parameter handling with Action/Resource handler

Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
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...
thumbnail
Sơn Tuấn Nguyễn, modifié il y a 11 années.

RE: Parameter handling with Action/Resource handler

Junior Member Publications: 37 Date d'inscription: 02/03/10 Publications récentes
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.
thumbnail
Sơn Tuấn Nguyễn, modifié il y a 11 années.

RE: Parameter handling with Action/Resource handler

Junior Member Publications: 37 Date d'inscription: 02/03/10 Publications récentes
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.