Reputation: 175
What is the actual difference between doView()
and render()
functions in Liferay? and also what is the difference between renderRequest
and resourceRequest
?
Upvotes: 7
Views: 10039
Reputation: 1
"In Liferay, doView and render are functions used in portlet development to handle different phases of the portlet lifecycle.
doView Method: This method is part of the javax.portlet.GenericPortlet class and is called to generate the view mode of the portlet. It is typically overridden to include the logic for rendering the main content of the portlet. The doView method is used when the portlet is in its normal view state.
@Override
protected void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
// Your view logic here
}
render Method: This method belongs to the javax.portlet.Portlet interface and serves as a more generic entry point for rendering content. The render method can handle all render requests, not just those for the view mode. It's less common to override this method directly, as doView, doEdit, and doHelp are more specific and convenient for handling their respective modes.
@Override
public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException {
// Your render logic here
}
In summary, doView is specific to the view mode of a portlet, while render can handle any render phase but is less commonly used to particular modes due to the convenience of doView, doEdit, and doHelp."
Upvotes: -1
Reputation: 749
doView()
= to handle render requests when in VIEW mode.
render()
= This method invokes the doDispath()
method and sets the title of the portlet by using getTitle()
method. Then it invokes one of doView()
, doEdit()
, doHelp()
, etc. depending of the portlet mode specified in the RenderRequest
.
Again, RenderRequest is when you want to handle requests in the VIEW mode of the portlet. If your portlet uses additional resources to render the view (i.e. images, JavaScript files, etc.) then the JSP that renders the view will use <portlet:resourceURL />
tags to generate valid URLs to those resources. Those URLs will be processed with a pair of ResourceRequest
and ResourceResponse
objects.
You can override the resource phase though but bear in mind that when you use ResourceRequest
/ResourceResponse
to serve, the portlet can't change the current portlet mode, window state or render parameters. And also the parameters set on the resource urls are not the render parameters and they are valid to serve only that current resource request.
Upvotes: 9