PDA

View Full Version : resolve view name from handleActionRequestInternal(ActionRequest ActionResponse)


bred
Mar 11th, 2008, 01:32 AM
Hi,

I am using Struts all the time and recently started working spring portlet API to support one of our client. In struts action class I can redirect to any random view based on my business logic. How can i accomplish same thing in action request of portlet. for example while executing handleActionRequestInternal(ActionRequest ActionResponse) how can i forward different views conditionally.

Thanks in advance.

Bred

johnalewis
Mar 14th, 2008, 03:00 PM
Spring Web MVC (i.e. servlets) have a forward mechanism that is quite similar to Struts.

Portlets are quite different from Servlets, and there is no forward mechanism available in the standard. However, given the two-phase nature of the portlet request (action/render) it is possible to do essentially the same thing. During the action phase, change the conditions used by the HandlerMapping to determine which Controller and View will be selected. Then when the render phase begins, the request will go to the desired location.

There is a tip about this in the JavaDoc for AbstractController (http://static.springframework.org/spring/docs/2.0.x/api/org/springframework/web/portlet/mvc/AbstractController.html):

TIP: The controller mapping will be run twice by the PortletDispatcher for action requests -- once for the action phase and again for the render phase. You can reach the render phase of a different controller by simply changing the values for the criteria your mapping is using, such as portlet mode or a request parameter, during the action phase of your controller. This is very handy since redirects within the portlet are apparently impossible. Before doing this, it is usually wise to call clearAllRenderParameters and then explicitly set all the parameters that you want the new controller to see. This avoids unexpected parameters from being passed to the render phase of the second controller, such as the parameter indicating a form submit ocurred in an AbstractFormController.

Hope that helps!

bred
Apr 13th, 2008, 10:46 PM
Thanks for your help.