I am developing a custom portlet (EDIT:I'm extending MVCPortlet), and looking at several examples and tutorials, I find that when the doView(RenderRequest, RenderResponse) method is overridden, at the end of it there is always at least this line:
super.doView(renderRequest, renderResponse);
or this:
include(viewJSP, renderRequest, renderResponse);
If I don't put either of these my portlet doesn't render anything, but any of them does the trick.
I would like to know which one I should be using, and why do I need to add them to get my portlet to work.
Thanks!
So you must be extending MVCPortlet
class. Both the calls are used to include the JSP after the doView
processing is completed. If you look at the source code of this class then you would understand what the flow is, below is my explanation:
super.doView(renderRequest, renderResponse);
This includes the default JSP i.e. view.jsp
, that you might (or not) have configured in portlet.xml
something like this:
<init-param>
<name>view-template</name>
<value>/html/view.jsp</value>
</init-param>
This super class method does nothing but calls the include(viewJSP, renderRequest, renderResponse);
method at the end.
include(viewJSP, renderRequest, renderResponse);
This method includes whatever JSP path you have specified for the parameter viewJSP
. So with this call you can specify including different JSP for different condition something like the following:
if (isThisTrue) {
include("/html/myCustomPortlet/view.jsp", renderRequest, renderResponse);
} else if (isThisTrueThen) {
include("/html/myCustomPortlet/first/another_view.jsp", renderRequest, renderResponse);
} else {
super.doView(renderRequest, renderResponse);
}
So depending on your requirement you can use any to the two or the mix of the two as shown above. Hope this helps.
The include lets you specify a different JSP to use instead of the default view. So if you are not using a custom view page either will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With