Multiple pages within a single portlet

I am wondering if anyone knows if it is possible for a single portlet to contain multiple pages, say, JSP pages. Also, is it possible to link these pages to the same portlet?

For example. Say I have one portlet. And in this portlet, I want the initial view to be a JSP page with 5 links to it on 5 different JSP pages. And when the user clicked on one of these 5 links, he will load the corresponding JSP page into the portlet.

The final goal will basically be a small mini-site contained within the portlet.

Now I understand that this may not be the best way to use the portlet, but for the project I'm working on, I still would like to know if this is possible.

Thanks!

+3
source share
1 answer

Of course, a portlet can contain more than one JSP.

You can display any JSP you want using PortletRequestDispatcher in doView (or doHelpor doEdit):

protected void doView(RenderRequest req, RenderResponse resp)
       throws PortletException, IOException, UnavailableException {
   resp.setContentType("text/html"); 
   String myview = req.getParameter("myview");
   String view = "/WEB-INF/jsp/" + (myview==null ? "bar" : myview) + ".jsp";
   PortletRequestDispatcher dispatcher = 
                                 getPortletContext().getRequestDispatcher(view);
   dispatcher.include(req, resp);
}

To set the view, you can use parameter . In JSP with links, you will need to use the portlet API to create / encode portlet links. For example:

<portlet:renderURL>
  <portlet:param name="myview" value="foo"/>
</portlet:renderURL>

(I really didn’t know about JSR286 / Portlet 2.0 - this material should work with JSR168 / Portlet 1.0, so you should check out the new API if you use it.)

+4
source

Source: https://habr.com/ru/post/1717379/


All Articles