Foren

Pass parameter before portlet render

cyril arrighi, geändert vor 12 Jahren.

Pass parameter before portlet render

New Member Beiträge: 21 Beitrittsdatum: 23.06.11 Neueste Beiträge
Hello,
I'm wondering how to pass parameter to a portlet ?
I have a combobox in my view.jsp that lists the persons, but before rendering my view (for the first time) i'd like to retrieve all the persons from the database and pass the array as an init parameter but i don't know how to do that.
Thanks
thumbnail
Krishna Melkote, geändert vor 12 Jahren.

RE: Pass parameter before portlet render

Junior Member Beiträge: 52 Beitrittsdatum: 22.09.10 Neueste Beiträge
Looking at what you are trying to do .. it should be fairly straightforward..
You should just be able to set the "Persons" in the request as an attribute or on the model (if you are using Spring etc)


                 doView(RenderRequest request, RenderResponse response) {
                          // Check if it is an initial request by means of a commandType or something like that in request parameters
                          if(initialRequest){
                                    // Do your jdbc stuff and retrieve Persons from the database
                                    
                                    // set the persons in the request, this will be available in the view you are trying to render by doing a request.getAttribute("persons")
                                    request.setAttribute("persons", persons);

                           }
                  }
cyril arrighi, geändert vor 12 Jahren.

RE: Pass parameter before portlet render

New Member Beiträge: 21 Beitrittsdatum: 23.06.11 Neueste Beiträge
Hi,
Sorry i forgot to mention that i'm using MVC portlet, so i suppose that i've to use the doView method ?
And so, what is the condition i've to use,
if(initialRequest)
?
Thanks
cyril arrighi, geändert vor 12 Jahren.

RE: Pass parameter before portlet render

New Member Beiträge: 21 Beitrittsdatum: 23.06.11 Neueste Beiträge
nobody ? emoticon
prashant deshpande, geändert vor 12 Jahren.

RE: Pass parameter before portlet render

New Member Beiträge: 16 Beitrittsdatum: 17.06.10 Neueste Beiträge
Hi Cyril,

Here before calling your view.jsp,
doView(RenderRequest renderRequest, RenderResponse renderResponse) method is called very first (Weather its MVC, Spring etc).
So you can write your logic of fetching list of person from Database and setting it in request. So in view.jsp you can get as request attribute.
Please let me know in case of any confusion.
thumbnail
Sagar A Vyas, geändert vor 12 Jahren.

RE: Pass parameter before portlet render

Liferay Master Beiträge: 679 Beitrittsdatum: 17.04.09 Neueste Beiträge
cyril arrighi:
Hello,
I'm wondering how to pass parameter to a portlet ?
I have a combobox in my view.jsp that lists the persons, but before rendering my view (for the first time) i'd like to retrieve all the persons from the database and pass the array as an init parameter but i don't know how to do that.
Thanks



Hi Cyril,

Following is flow of MVC portlet (In you case)

Portlet.xml >> Controller Class (Which has extended MVCPortlet ) >> it will call doVIew() Method of MVCPortlet >> view.jsp

Now here there in no place where you can set some renderParameter which you can retrieve in jsp and display,

Solution :

Just override method doView() in your controller class. >> get those data from service layer >> set an attributes and retrieve it at jsp side

This will solve your problem emoticon

Thanks,
Sagar Vyas
cyril arrighi, geändert vor 12 Jahren.

RE: Pass parameter before portlet render

New Member Beiträge: 21 Beitrittsdatum: 23.06.11 Neueste Beiträge
Hello,
It works, thanks emoticon