JBoss Community Archive (Read Only)

GateIn Portal 3.8

Navigation Portlet Using the Public API

Among other things, Portal API can be used for implementing a Navigation Portlet. You may want to read Starting a Portlet Project and Standard Portlet Development (JSR 286) before you proceed.

Example Code

This section cites code from Navigation API Portlet from the Quickstarts Collection.

pom.xml

There is only one noticeable difference in pom.xml against the general case presented in Starting a Portlet Project: we only need to add the gatein-api dependency:Code Snippet error: Unable to retrieve the URL: https://github.com/gatein/gatein-portal-quickstart/raw/master/navigation-api-portlet/pom.xml status code: 404.

The Java Part

There are only two classes necessary to implement the Navigation Portlet: NavigationPortlet and NavigationNodeBean.

The NavigationPortlet.doView(RenderRequest, RenderResponse) method is responsible for the rendering of the main, always visible menu.Code Snippet error: Unable to retrieve the URL: https://github.com/gatein/gatein-portal-quickstart/raw/master/navigation-api-portlet/src/main/java/org/gatein/portlet/quickstart/navigation/NavigationPortlet.java status code: 404.

The NavigationPortlet.serveResource(ResourceRequest, ResourceResponse) method serves the AJAX requests to render sub-menus. For a given sub-menu URI, it returns a HTML fragment containing the sub-menu.Code Snippet error: Unable to retrieve the URL: https://github.com/gatein/gatein-portal-quickstart/raw/master/navigation-api-portlet/src/main/java/org/gatein/portlet/quickstart/navigation/NavigationPortlet.java status code: 404.

The NavigationNodeBean serves as a model and contains all the information being rendered on the page. In the NavigationPortlet.doView() method, the navigationRootNodeBean field is representing the root node of the navigation and contains main menu (top-menu) elements (Home and Sitemap by default) as children nodes.

The JSP Part

We have chosen to use JSP (JavaServer Pages) for rendering.

The navigation.jsp file is encapsulates the node.jsp output into an element with unique id identifier:Code Snippet error: Unable to retrieve the URL: https://github.com/gatein/gatein-portal-quickstart/raw/master/navigation-api-portlet/src/main/webapp/jsp/navigation.jsp status code: 404.

The node.jsp file is responsible for rendering the menus. Please note, that the HTML comment tag does not disable the JSP code, and it is used just to get rid of the whitespace for more precise CSS styling:Code Snippet error: Unable to retrieve the URL: https://github.com/gatein/gatein-portal-quickstart/raw/master/navigation-api-portlet/src/main/webapp/jsp/node.jsp status code: 404.

The JavaScript Part

The JavaScript part was implemented as a JQuery plugin. It has several roles:

  • AJAX support

  • Basic on-click drop-down support

  • Dynamically respond to window changes, position menus within the browser window

The asynchronous requests use the JQuery ajax() method:Code Snippet error: Unable to retrieve the URL: https://github.com/gatein/gatein-portal-quickstart/raw/master/navigation-api-portlet/src/main/webapp/js/dropdown.jquery.js status code: 404.

For more details about the implementation, please see the comments in the (dropdown.jquery.js) file.

Further Steps

After having understood all the above, it is time to build and deploy the portlet, import it and add it to a page so that you can test its functionality.

See also

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-10 13:19:41 UTC, last content change 2013-05-30 14:55:11 UTC.