Articles
Java Platform, Enterprise Edition
|
|
| By Satya Ranjan, February 2008 |
|
This article describes portlet development using NetBeans Portal Pack 2.0 Beta and Java Application Platform SDK Update 4.
Note: See the NetBeans Portal Pack 2.0 Beta Release Notes and Installation Instructions.
NetBeans Portal Pack 2.0 Beta makes portlet development as easy as writing normal Java applications; with all the features of portlets made available to you at the click of a mouse. NetBeans Portal Pack 2.0 Beta is a plugin that extends the functionality of NetBeans IDE 6.0 to enable creation of portlets.
This plugin can also be used to create JSR 286 portlet applications. For more information, read this article.
The following software is required to create JSR 168 portlet applications mentioned in this article.
You can install the above mentioned software in any of the following ways:
NetBeans Portal Pack 2.0 Beta can be used to deploy and undeploy portlets on an already installed portlet container in any of the following scenarios:
For installation instructions, visit:
You will need to configure a portlet container instance inside your NetBeans IDE. Please see the Appendix for further details.
In this article, we will provide a step-by-step walkthrough on:
The following section discusses how to create a Hello World portlet.
Figure 1: New Portlet Wizard
|
The Hello World portlet application is now created with a default HelloWorld portlet class file and the relevant JSP files. The portlet.xml file is updated with the portlet created in the above step. The HelloWorld portlet will display the string " HelloWorld - VIEW MODE" when it is executed and viewed on a browser.
The following section describes how to run portlets in NetBeans IDE 6.0.
To run the portlet, right-click on the project and click "Run." The IDE will first deploy the portlet on the portlet container configured at the time of the project creation. When the deployment succeeds, the IDE will open the NetBeans-configured browser and display the portlet "Hello World" within the portlet container driver.
The following section provides an approach to deploy the portlet application that one just created.
You can either undeploy the portlets or view the portlets at this point by right-clicking on the portlet node.
This section provides an overview of the basic template of a portlet application created by NetBeans Portal Pack 2.0 Beta.
public void doView(RenderRequest request,RenderResponse response)
throws PortletException,IOException {
response.setContentType("text/html");
PortletRequestDispatcher dispatcher =
getPortletContext().getRequestDispatcher("/WEB-
INF/jsp/HelloWorld_view.jsp");
dispatcher.include(request, response);
}
public void doEdit(RenderRequest request,RenderResponse response)
throws PortletException,IOException {
response.setContentType("text/html");
PortletRequestDispatcher dispatcher =
getPortletContext().getRequestDispatcher("/WEB-
INF/jsp/HelloWorld_edit.jsp");
dispatcher.include(request, response);
}
public void doHelp(RenderRequest request, RenderResponse response)
throws PortletException,IOException {
response.setContentType("text/html");
PortletRequestDispatcher dispatcher =
getPortletContext().getRequestDispatcher("/WEB-
INF/jsp/HelloWorld_help.jsp");
dispatcher.include(request, response);
|
Build and deploy the portlet. When the portlet is executed, it will display a "HelloWorld - VIEW MODE" string.
Figure 2. Output of the HelloWorld Portlet
Click here for a larger image. |
You can similarly create a Portlet 1.0 application by selecting the "1.0" portlet version during project creation. And the portlet 1.0 application can be deployed on Portlet Container 1.0.2 (comes with Java Application Platform SDK Update 4).
Please send feedback to users@portalpack.netbeans.org.
Configure Portlet Container in NetBeans
|