Vista combinada Visión Plana Vista de árbol
Discusiones [ Anterior | Siguiente ]
toggle
Sơn Tuấn Nguyễn
Parameter handling with Action/Resource handler
18 de agosto de 2012 22:57
Respuesta

Sơn Tuấn Nguyễn

Ranking: Junior Member

Mensajes: 37

Fecha de incorporación: 1 de marzo de 2010

Mensajes recientes

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 de agosto de 2012 1:34
Respuesta

Satheesh Ravi

Ranking: Junior Member

Mensajes: 35

Fecha de incorporación: 24 de noviembre de 2011

Mensajes recientes

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 de agosto de 2012 4:48
Respuesta

Mayur Patel

Ranking: Expert

Mensajes: 342

Fecha de incorporación: 17 de noviembre de 2010

Mensajes recientes

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 de agosto de 2012 2:10
Respuesta

Sơn Tuấn Nguyễn

Ranking: Junior Member

Mensajes: 37

Fecha de incorporación: 1 de marzo de 2010

Mensajes recientes

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 de agosto de 2012 2:25
Respuesta

Sơn Tuấn Nguyễn

Ranking: Junior Member

Mensajes: 37

Fecha de incorporación: 1 de marzo de 2010

Mensajes recientes

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 de agosto de 2012 19:52
Respuesta

Sơn Tuấn Nguyễn

Ranking: Junior Member

Mensajes: 37

Fecha de incorporación: 1 de marzo de 2010

Mensajes recientes

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

Andew Jardine

Ranking: Expert

Mensajes: 472

Fecha de incorporación: 22 de diciembre de 2010

Mensajes recientes

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 de agosto de 2012 20:53
Respuesta

Sơn Tuấn Nguyễn

Ranking: Junior Member

Mensajes: 37

Fecha de incorporación: 1 de marzo de 2010

Mensajes recientes

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 de agosto de 2012 21:40
Respuesta

David H Nebinger

Community Moderator

Ranking: Liferay Legend

Mensajes: 8589

Fecha de incorporación: 1 de septiembre de 2006

Mensajes recientes

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 de agosto de 2012 23:50
Respuesta

Sơn Tuấn Nguyễn

Ranking: Junior Member

Mensajes: 37

Fecha de incorporación: 1 de marzo de 2010

Mensajes recientes

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 de agosto de 2012 1:07
Respuesta

Sơn Tuấn Nguyễn

Ranking: Junior Member

Mensajes: 37

Fecha de incorporación: 1 de marzo de 2010

Mensajes recientes

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.