What is the difference between super.doView (...) and include (...) on doView overrides?

I am developing my own portlet (EDIT: I am expanding MVCPortlet), and looking at a few examples and tutorials, I found that when the doView method (RenderRequest, RenderResponse) is overridden, there is always at least this line at the end:

super.doView(renderRequest, renderResponse); 

or that:

 include(viewJSP, renderRequest, renderResponse); 

If I do not put any of these, my portlet does not display anything, but any of them does the trick.

I would like to know which one I should use, and why should I add them to make the portlet work.

Thanks!

+4
source share
2 answers

So you have to extend the MVCPortlet class. Both calls are used to include JSP after doView processing is doView . If you look at the source code of this class, then you will understand what a stream is, below is my explanation:

super.doView (renderRequest, renderResponse);

This includes the default JSP, i.e. view.jsp , which you could (or not) configure in portlet.xml like this:

 <init-param> <name>view-template</name> <value>/html/view.jsp</value> </init-param> 

This superclass method does nothing but call the include(viewJSP, renderRequest, renderResponse); method include(viewJSP, renderRequest, renderResponse); in the end.

include (viewJSP, renderRequest, renderResponse);

This method includes any JSP path that you specified for the viewJSP parameter. Thus, with this call you can specify, including different JSPs for different conditions, 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); } 

Thus, depending on your requirement, you can use either of the two or a combination of the two, as shown above. Hope this helps.

+8
source

Inclusion allows you to specify a different JSP to use instead of the default view. Therefore, if you do not use the user view page, it will work.

+1
source

All Articles