掲示板

Parameter handling with Action/Resource handler

thumbnail
11年前 に Sơn Tuấn Nguyễn によって更新されました。

Parameter handling with Action/Resource handler

Junior Member 投稿: 37 参加年月日: 10/03/02 最新の投稿
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.
11年前 に Satheesh Ravi によって更新されました。

RE: Parameter handling with Action/Resource handler

Junior Member 投稿: 35 参加年月日: 11/11/25 最新の投稿
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
11年前 に Mayur Patel によって更新されました。

RE: Parameter handling with Action/Resource handler

Expert 投稿: 358 参加年月日: 10/11/17 最新の投稿
Exactly, Agree with Satheesh, you can use serverResource method only for this kind of problem
thumbnail
11年前 に Sơn Tuấn Nguyễn によって更新されました。

RE: Parameter handling with Action/Resource handler

Junior Member 投稿: 37 参加年月日: 10/03/02 最新の投稿
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
11年前 に Sơn Tuấn Nguyễn によって更新されました。

RE: Parameter handling with Action/Resource handler

Junior Member 投稿: 37 参加年月日: 10/03/02 最新の投稿
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
11年前 に Sơn Tuấn Nguyễn によって更新されました。

RE: Parameter handling with Action/Resource handler

Junior Member 投稿: 37 参加年月日: 10/03/02 最新の投稿
Still looking for a solution.
thumbnail
11年前 に Andew Jardine によって更新されました。

RE: Parameter handling with Action/Resource handler

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
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
11年前 に Sơn Tuấn Nguyễn によって更新されました。

RE: Parameter handling with Action/Resource handler

Junior Member 投稿: 37 参加年月日: 10/03/02 最新の投稿
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
11年前 に David H Nebinger によって更新されました。

RE: Parameter handling with Action/Resource handler

Liferay Legend 投稿: 14915 参加年月日: 06/09/02 最新の投稿
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
11年前 に Sơn Tuấn Nguyễn によって更新されました。

RE: Parameter handling with Action/Resource handler

Junior Member 投稿: 37 参加年月日: 10/03/02 最新の投稿
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
11年前 に Sơn Tuấn Nguyễn によって更新されました。

RE: Parameter handling with Action/Resource handler

Junior Member 投稿: 37 参加年月日: 10/03/02 最新の投稿
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.