Foros de discusión

MVCPortlet doView method

thumbnail
Zsolt - Jácint Balogh, modificado hace 8 años.

MVCPortlet doView method

Junior Member Mensajes: 91 Fecha de incorporación: 9/10/13 Mensajes recientes
Hi all,

I have a lot of logic in my jsp page and I want to put the logic to a java class.
There is a way when the doView is not called in the render phase?

I'm using com.liferay.util.bridges.mvc.MVCPortlet with liferay 6.2.

Regards,
Zsolt
thumbnail
Andrew Jardine, modificado hace 8 años.

RE: MVCPortlet doView method

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
Hi Zsolt,

I'm not sure I understand exactly what you are looking for. If you want to move the logic from the JSP to java classes you can create your own XXXPortlet class that extends the MVCPortlet, and then override the render method and move your JSP logic into there.

Is that what you are looking for?
thumbnail
Zsolt - Jácint Balogh, modificado hace 8 años.

RE: MVCPortlet doView method

Junior Member Mensajes: 91 Fecha de incorporación: 9/10/13 Mensajes recientes
I want exactly that.
My portlet has to work other way based on different public render parameters.
So I want to remove the logic from the JSP put that into the doView method and use the result of the logic in the JSP.

My question is that is that OK if I overwrite the doView?
As I know the doView will run all the time when the portlet renders so I think yes.
One of my colleague mentioned once that there are some exception cases when the doView is not called. If so what are those cases?

Thanks,
Zsolt
thumbnail
Andrew Jardine, modificado hace 8 años.

RE: MVCPortlet doView method

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
Hi Zolt,

I don't normally work directly with the doView but rather the 2.0 spec render method. So your portlet.xml would look something like this --


 <portlet>
    	<portlet-name>xxx-portlet</portlet-name>
    	<display-name>XXX Portlet</display-name>
    	<portlet-class>com.my.custom.package.XXXPortlet</portlet-class>
    	<init-param>
    		<name>view-template</name>
    		<value>view.jsp</value>
    	</init-param>
    	<init-param>
        ....   
</init-param></portlet>


and then in the portlet class just make sure that the last statement in the render method is a super call so that you don't lose the magic Liferay provides for you.


    public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException
    {
        // Your public render parameter logic and stuff here

        super.render(renderRequest, renderResponse);  // make sure this is the last  line in your method
    }



That should do it for you.
thumbnail
Zsolt - Jácint Balogh, modificado hace 8 años.

RE: MVCPortlet doView method (Respuesta)

Junior Member Mensajes: 91 Fecha de incorporación: 9/10/13 Mensajes recientes
Thanks, I will use the render method instead of doView.
Abid Mehmood, modificado hace 7 años.

RE: MVCPortlet doView method

Junior Member Mensajes: 66 Fecha de incorporación: 8/09/11 Mensajes recientes
Hi Andrew,

Andrew Jardine:

and then in the portlet class just make sure that the last statement in the render method is a super call so that you don't lose the magic Liferay provides for you.

.

I might be missing quite the obvious thing but would you mind explaining me this liferay magic part, when does liferay comes into the picture. Offcourse you are extending the MVC portlet but all you are doing is using Generic portlets class methods(render method).
thumbnail
Andrew Jardine, modificado hace 7 años.

RE: MVCPortlet doView method

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
Hi Abid,

Fair point -- but I believe the expression to describe the benefit here is "Future Proofing". Your point is valid though, the render() method called today is simply the one from the GenericPortlet implementation, but who's to say that in the next release there won't be an overridden version added to the LiferayPortlet or the MVCPortlet class?

I think really it boils down to less about the "magic" statement -- which was inaccurate in this case -- and more about the v2.0 of the spec. I certainly wasn't suggesting that you can't use doView, many people still do. Personally, when I am building Liferay applications, I find it easiest to follow Liferay's patterns and conventions used in their own source code and it makes it easier to switch between Liferay's source code and my own.

In the end though, the choice is always yours of course.