Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Ken Driscoll
Setting "jspPage" as renderParameter not changing displayed jsp
July 19, 2012 12:42 PM
Answer

Ken Driscoll

Rank: Junior Member

Posts: 57

Join Date: July 2, 2012

Recent Posts

I am trying to change the jsp page that will be displayed after my action method is called.

In my method, I am calling:
1actionResponse.setRenderParameter("jspPage", "/otherPage.jsp");


However, this doesn't work for me...it has no effect on the page that is displayed. Am I doing something wrong? Or is there something else I should be doing?
Pinkesh Gandhi
RE: Setting "jspPage" as renderParameter not changing displayed jsp
July 20, 2012 4:37 AM
Answer

Pinkesh Gandhi

Rank: Regular Member

Posts: 100

Join Date: January 26, 2012

Recent Posts

Hi Ken,

If you are using simple jsp-portlet or MVCPortlet then in doView(...) method of your portlet, have you implemented conditions for this 'jspPage' parameter like in the following way

 1
 2public void doView(RenderRequest renderRequest,    RenderResponse renderResponse) throws IOException, PortletException {
 3       
 4        String jspPage = ParamUtil.getString(renderRequest, "jspPage", "<default-landing-jsp-page-path>");
 5       
 6        if(jspPage.equalsIgnoreCase("/login.jsp")){
 7            /*
 8             * Write your code for login page 
 9             */
10            this.include("<path-of-login.jsp>", renderRequest, renderResponse);
11        }else if(jspPage.equalsIgnoreCase("/registration.jsp")){
12            /*
13             * Write your code for registration page 
14             */
15            this.include("<path-of-registration.jsp>", renderRequest, renderResponse);
16        }else{
17            /*
18             * Write your code for default landing page 
19             */
20            this.include("<path-of-default-landing-jsp>", renderRequest, renderResponse);
21        }
22    }


This is just an example code snippet which indicates the way you have to implement the doView(...) method.

Hope this will helps you.

Let me know if you have any query for the same.
DarshanKumar N Bhatia
RE: Setting "jspPage" as renderParameter not changing displayed jsp
July 20, 2012 5:05 AM
Answer

DarshanKumar N Bhatia

Rank: Junior Member

Posts: 85

Join Date: March 2, 2010

Recent Posts

Which Portlet MVC have u used ?
--- Liferay MVC ..

import com.liferay.util.bridges.mvc.MVCPortlet;

public class DemoPortlet extends MVCPortlet{

public void processAction(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
System.out.println("inside save data");
actionResponse.setRenderParameter("jspPage","/result-chart.jsp"); // forward to jsp
}

}

-----In case of generic Portlet : http://www.javabeat.net/2011/03/portlets-are-easy/
HTH...
Ken Driscoll
RE: Setting "jspPage" as renderParameter not changing displayed jsp
July 20, 2012 6:13 AM
Answer

Ken Driscoll

Rank: Junior Member

Posts: 57

Join Date: July 2, 2012

Recent Posts

DarshanKumar N Bhatia:
Which Portlet MVC have u used ?
--- Liferay MVC ..

import com.liferay.util.bridges.mvc.MVCPortlet;

public class DemoPortlet extends MVCPortlet{

public void processAction(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
System.out.println("inside save data");
actionResponse.setRenderParameter("jspPage","/result-chart.jsp"); // forward to jsp
}

}

-----In case of generic Portlet : http://www.javabeat.net/2011/03/portlets-are-easy/
HTH...


This is legit exactly what I am doing...(the Liferay MVCPortlet part). Is there some property I need to set/unset for this to work?
Pinkesh Gandhi
RE: Setting "jspPage" as renderParameter not changing displayed jsp
July 20, 2012 6:29 AM
Answer

Pinkesh Gandhi

Rank: Regular Member

Posts: 100

Join Date: January 26, 2012

Recent Posts

Hi Ken,

There is no any option what you are looking for MVCPortlet / GenricPortlet.

As I've replied in your another similar kind of thread http://www.liferay.com/community/forums/-/message_boards/message/14950922 and again I say same thing here that,

As per the portlet life cycle, if you have not used sendRedirect method in processAction(...) then after completion of execution of your processAction(...) method the doView(...) method will be executed immediately.

So you have to implement conditions in your doView(...) method.
Ken Driscoll
RE: Setting "jspPage" as renderParameter not changing displayed jsp
July 20, 2012 6:34 AM
Answer

Ken Driscoll

Rank: Junior Member

Posts: 57

Join Date: July 2, 2012

Recent Posts

Pinkesh,

I have print statements in both my overriden processAction and doView methods. In my case, doView only seems to be called when an renderURL is called, and is not called after any time my processAction is called. After my processAction is called, it immediately goes into my custom action-method specified in my actionURL. Do I need to call something at the end of my action-method to make it fall into the doView?
Pinkesh Gandhi
RE: Setting "jspPage" as renderParameter not changing displayed jsp
July 20, 2012 6:34 AM
Answer

Pinkesh Gandhi

Rank: Regular Member

Posts: 100

Join Date: January 26, 2012

Recent Posts

And to avoid such kind of pathetic things, I suggest you can use @annotation based spring-mvc portlet.
Pinkesh Gandhi
RE: Setting "jspPage" as renderParameter not changing displayed jsp
July 20, 2012 6:37 AM
Answer

Pinkesh Gandhi

Rank: Regular Member

Posts: 100

Join Date: January 26, 2012

Recent Posts


I have print statements in both my overriden processAction and doView methods. In my case, doView only seems to be called when an renderURL is called, and is not called after any time my processAction is called. After my processAction is called, it immediately goes into my custom action-method specified in my actionURL. Do I need to call something at the end of my action-method to make it fall into the doView?



If it is convenient for you, can you please attach your code of doView(...) and processAction(...) methods here.
Ken Driscoll
RE: Setting "jspPage" as renderParameter not changing displayed jsp
July 20, 2012 6:48 AM
Answer

Ken Driscoll

Rank: Junior Member

Posts: 57

Join Date: July 2, 2012

Recent Posts

Ok, here is what I call in my jsp:

1<portlet:actionURL var="nextPageURL" name="doNextPage">
2    <portlet:param name="jspPage" value="/nextPage.jsp" />
3</portlet:actionURL>


And here is my extended MVCPortlet.

 1public class MyPortlet extends MVCPortlet
 2{
 3        public void doNextPage(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException
 4    {
 5                System.out.println("in doNextPage");
 6        actionResponse.setRenderParameter("jspPage", "/other.jsp");  //Should change displayed jsp but doesn't
 7    }
 8
 9
10    @Override
11    public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException
12    {
13        System.out.println("IN PROCESS ACTION");
14        String jspPage = actionRequest.getParameter("jspPage");
15        System.out.println("Attempting to access: "+jspPage);
16       
17        super.processAction(actionRequest, actionResponse);
18    }
19
20       @Override
21    public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
22        System.out.println("IN DO VIEW");
23        super.doView(renderRequest, renderResponse);
24    }
25
26}


When I submit to the actionURL, I get the following output:

1IN PROCESS ACTION
2Attempting to access: /nextPage.jsp
3in doNextPage
Svetoslav Kostadinov
RE: Setting "jspPage" as renderParameter not changing displayed jsp
July 20, 2012 7:16 AM
Answer

Svetoslav Kostadinov

Rank: New Member

Posts: 6

Join Date: June 27, 2012

Recent Posts

I think your /nextPage.jsp can't be found.

try to write the full path from docroot... /html/your-project-name/nextPage.jsp

or whatever is yours...

see what happens
Pinkesh Gandhi
RE: Setting "jspPage" as renderParameter not changing displayed jsp
July 20, 2012 7:17 AM
Answer

Pinkesh Gandhi

Rank: Regular Member

Posts: 100

Join Date: January 26, 2012

Recent Posts

A probable solution for your current scenario is,

 1
 2   @ProcessAction(name="doNextPage")
 3   public void doNextPage(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException {
 4                System.out.println("in doNextPage");
 5                actionResponse.setRenderParameter("jspPage", "/other.jsp");  //Should change displayed jsp but doesn't
 6    }
 7
 8    @Override
 9     public void doView(RenderRequest renderRequest,
10            RenderResponse renderResponse) throws IOException, PortletException {
11       
12        String jspPage = ParamUtil.getString(renderRequest, "jspPage", "<default-landing-jsp-page-path>");
13       
14        if(jspPage.equalsIgnoreCase("/login.jsp")){
15            /*
16             * Write your code for login page 
17             */
18            this.include("<path-of-login.jsp>", renderRequest, renderResponse);
19        }else if(jspPage.equalsIgnoreCase("/registration.jsp")){
20            /*
21             * Write your code for registration page 
22             */
23            this.include("<path-of-registration.jsp>", renderRequest, renderResponse);
24        }else{
25            /*
26             * Write your code for default landing page 
27             */
28            this.include("<path-of-default-landing-jsp>", renderRequest, renderResponse);
29        }
30    }   

Please note here two things I've changed in your code
(1) Adding @ProcessAction(name="doNextPage") on doNextPage(..) method
(2) Removing processAction(..) method as doNextPage(..) method will be treated as a processAction method of your portlet and you can add such methods as many as you want.


Another thing I would like to suggest is, to just displaying other page don't use 'actionUrl'. You can simply achieve it by using 'renderUrl'.
For this scenario, please see my code snippet below

1
2<portlet:renderURL var="nextPageURL">
3    <portlet:param name="jspPage" value="/nextPage.jsp" />
4</portlet:renderURL>


 1
 2       @Override
 3    public void doView(RenderRequest renderRequest,
 4            RenderResponse renderResponse) throws IOException, PortletException {
 5       
 6        String jspPage = ParamUtil.getString(renderRequest, "jspPage", "<default-landing-jsp-page-path>");
 7       
 8        if(jspPage.equalsIgnoreCase("/nextPage.jsp")){
 9            /*
10             * Write your code for next page 
11             */
12            this.include("<write-path-of-nextPage.jsp>", renderRequest, renderResponse);
13        }else if(jspPage.equalsIgnoreCase("/registration.jsp")){
14            /*
15             * Write your code for registration page 
16             */
17            this.include("<write-path-of-registration.jsp>", renderRequest, renderResponse);
18        }else{
19            /*
20             * Write your code for default landing page 
21             */
22            this.include("<write-path-of-default-landing-jsp-page>", renderRequest, renderResponse);
23        }
24    }


So in this case you don't need to write a separate processAction method for just rendering/displaying another page.
Ken Driscoll
RE: Setting "jspPage" as renderParameter not changing displayed jsp
July 20, 2012 7:23 AM
Answer

Ken Driscoll

Rank: Junior Member

Posts: 57

Join Date: July 2, 2012

Recent Posts

Pinkesh,

I want to keep the actionURL because I need to perform different actions depending what page I am calling. When I simply call a renderURL, only doView is called, not processAction. Do you possibly have another solution? I'm just slightly confused because all of the examples I have read say that my current set-up should work.
Ken Driscoll
RE: Setting "jspPage" as renderParameter not changing displayed jsp
July 20, 2012 7:28 AM
Answer

Ken Driscoll

Rank: Junior Member

Posts: 57

Join Date: July 2, 2012

Recent Posts

Svetoslav Kostadinov:
I think your /nextPage.jsp can't be found.

try to write the full path from docroot... /html/your-project-name/nextPage.jsp

or whatever is yours...

see what happens


Thank you for the feedback. nextPage.jsp is what is displaying. I am trying to change that in my action-method so it displays other.jsp instead. I tried the full path for my "other.jsp", but the same result occurred. Plus I don't believe that is the issue because no error was thrown.
Pinkesh Gandhi
RE: Setting "jspPage" as renderParameter not changing displayed jsp
July 23, 2012 2:46 AM
Answer

Pinkesh Gandhi

Rank: Regular Member

Posts: 100

Join Date: January 26, 2012

Recent Posts

I want to keep the actionURL because I need to perform different actions depending what page I am calling. When I simply call a renderURL, only doView is called, not processAction. Do you possibly have another solution?


Ken,

You can use actionURL also as per your requirement, and I've already provided solution in my previous reply for that also. Please look at the first code section of my previous reply.

One more thing, I would like to point out here that, while you are calling include(...) method from your doView method, you have to write complete path of your jsp page from docroot folder.

For e.g., if your jsp page resides under docroot/html/ test-portlet/ folder then you have to write complete path of your jsp like,

this.include("/html/test-portlet/other.jsp", renderRequest, renderResponse);

I hope this might resolve your problem.