1
votes

I'm trying to develop a basic portlet with LifeRay 6.1. I'm well versed with various MVC implementations, but I find Liferay / java portlets somewhat confusing - especially the execution pipeline.

With most MVC frameworks I've worked with the premise is simple request > router > controller > view. The view selection is usually based the controller / action naming convention, a parameter passed in with the request or is manually loaded in the controller action.

With LifeRay MVCPortlet it doesn't work like this; there's at least two types of URL that can be generated - a render url and an action url.

The render URL seems to totally bypass what I perceive to be the controller - a subclass of MVCPortlet. It seems as though these urls are relatively easy to generate and the request loads the expected view, if you can call it that considering for all intents and purposes it completely bypasses the controller and has nothing to do with a model.

<portlet:renderURL var="badminURL"><portlet:param name="mvcPath" value="/views/edit.jsp" /></portlet:renderURL>

The action URL goes through the controller, the action is called and then the default view is used to render the portlet regardless of what I supply as an mvc path.

<portlet:actionURL var="adminURL" name="editSlide"><portlet:param name="mvcPath" value="/views/edit.jsp" /></portlet:actionURL>

Reading up through the class tree I can see that a property is used to define the view that gets used depending on the portlet mode. i.e.

this.viewTemplate = "/views/edit.jsp";
this.editTemplate = "/views/edit.jsp";

Again setting this after init() is called only seems to have any effect when not accessed via an actionURL.

So I guess my question is pretty basic, how are views selected and how to I select one to use when going via an actionURL. Also any outline on execution pipeline would be very helpful

1

1 Answers

2
votes

I found the solution. You can allocate a render parameter on the ActionResponse object that is passed to the controller action. This tells liferay to load the supplied view. i.e.

public void editSlide(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException {

    // action code goes here

    // set up the view
    actionResponse.setRenderParameter("mvcPath", "/views/edit.jsp");        

}