Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Page Forward in Portlets

 
John Lincoln
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a Form Portlet, which takes the information from the user. I am processing the information in processAction method. After this i need to forward the user to another jsp. How can this be done ?

I cannot use PortletRequestDispatcher include method since it has normal RenderRequest and RenderResponse not ActionRequest and ActionResponse ?

Can you please throw some light ?
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Give me a bit of background...For instance, why can't you forward to the appropriate JSP from the doView method. The doView method will be invoked after the processAction.

You could add a parameter to the actionresponse, and read it in the renderresponse, and take the appropriate action depending upon this parameter. You could even put it in the portletsession if it were a permanent type of state change.

Here's a tutorial on rendering to JSP using a portlet:

Forwarding to a JSP from a Portlet

-Cameron McKenzie
 
John Lincoln
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply. I am rendering my first jsp in doView method which shows a form. After the user hits submit button, ( this information i am processing in process Action method), it should take the user to next page.
From processAction i cannot forward to second jsp. The PortalRequestDispatcher won't work since PortalRequestDispatcher's include method takes RenderRequest and RenderResponse and not ActionRequest &ActionResponse.

Please help.

thanks
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey John.

Here's what you're going to have to do. The ActionResponse has a method called setRenderParameter(key, value). What you'll have to do in the action processing phase is set something into the response:

setRenderParameter("pagetodisplay", "page2.jsp");

This will set the parameter in the action phase. Then you read it back in the render phase through.

String pageToDisplay = getParameter("pagetodisplay");

Then, in the doView method you have something like this:

if (pageToDisplay == null) {
//send user to the default landing page
}
else {
//send user to pageToDisplay
}

I think that's the way you're going to want to work it. Throw some data into the request or response object in the action phase, and then read it out during the view phase, and in the view phase, redirect to the appropriate page.

Think that will work?

-Cameron McKenzie
 
John Lincoln
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply. I tried your sugesstion, did not work as expected. Below is the code.

Here are my observations:
If i have just have following in the code, it works, but cannot see the next jsp


If i change it to


It says portlett is unavailable.

Following are doView and ProcessAction methods


BTW is doView called again after processAction ?.. Please help
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll have to look at the code for a bit.

But to answer your latter question, doView is indeed invoked after the event processing phase. Note though: the event processing phase isn't always called. The portlet has to be specifically invoked from an actionURL to trigger the action processing phase. Otherwise, the doView method is called.

Caching issues aside, the doView method of every portlet on the portal page is invoked when the portal renders a given portal page.

-Cameron McKenzie
 
John Lincoln
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have tried you suggestion again and it seems to work. Thank you very much.

I have to look into why i get message"This Portlet Unavailable" at the end of the form"

Can you provide me with any pointers.

thanks
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't see which portal you are using.

I get frustrated with the "Portlet Unavailable" message on JetSpeed2. I often stop the server, delete all references to the portlet application/war file, start the server, and then throw the war into the deploy directory. All of a sudden, a portlet that was unavailable becomes available again.

I can't tell you how much time I've wasted troubleshooting a portlet that was fully functional.

Happy Portal!

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic