Portal pack 3.0The Portal Pack 3.0 is now available for download. With lots of new features and bug fixes, the Portal Pack 3.0 is out there to make portlet development easier than before. This version is compatible with NetBeans 6.5 IDE. This version of Portal Pack supports the recently released Sun GlassFish Web Space Server 10.0 which is part of the GlassFish Portfolio.
WebSpace
Sun GlassFish Web Space Server is Sun’s next generation aggregation and presentaion platform.  It enables businesses large and small to pull together applications and content from a variety of Web-based and internal sources and present them as a unified, customizable portal on Web browsers, kiosks, and mobile devices. For more info you can check this blog written by James.

Some of the Key Features in Portal Pack 3.0

  • Support for New JSR 286 specification
  • Eventing Storyboard for JSR 286 Eventing
  • Visual Portlet Builder plug-in to build JSF portlet using WYSIWYG editor.
  • Portlets with Spring MVC framework
  • Write Portlets with different languages like Ruby/PHP/Groovy which can be deployed on Sun GlassFish Web Space Server and Liferay Portal Server.
  • Use Web Space/Liferay’s service builder framework inside your portlet. A new advanced Service XML editor is introduced to help you define and generate services.
  • Use Web Space/Liferay’s service apis directly to write advanced portlets.
  • Use Taglibs provided by Web Space/Liferay directly inside your Portlet. For example : You can use rich ui taglibs provided by Liferay/Web Space inside your Portlet, so that your portlet will look similar to other UI in the portal page.
  • Directory deployment : Using new directory deployment feature, you can quickly develop and test your application without redeploying your portlet application again and again. So no need to deploy your portlet when you are changing JSPs, HTML, javascripts etc etc… Also if you are developing portlets using PHP/Ruby/Groovy languages then you need to deploy the portlet only once during development cycle. During development, just change the PHP/Ruby/Groovy script and refesh the browser to see the output.

The deployment support in this release has been extended to support the following servers

Here’s the link to the  quick start guide for Portal Pack 3.0 . So try out this new Portal Pack 3.0  !!!

We have already started working on the next update for Portal Pack. Your feedback for the existing features and suggestions for any new features are most welcome. So you may see your suggested feature in the next update release of Portal Pack.

WebSynergy & Portal Pack at Devoxx’08

Posted: December 28, 2008 in Personal

I attended this year’s Devoxx conference which was held between 8th – 12th Dec at Antwerp, Belgium. This was my first trip to Devoxx conference and also to Belgium. I got an opportunity to talk about WebSynergy and Portal Pack in a 30 min session. It was mostly driven by the demos around WebSynergy and Portal Pack. I covered different kind of Portlet Developments using NetBeans and Portal Pack plug-ins.

Devoxx was definitely a success. It’s one of the biggest Java Community Conference in Europe.

There were some very good talks on JavaFX, JRuby, Flex, JBoss Seam. The videos of all those sessions of Devoxx’08 will be available at http://parleys.com/ sometime during Jan’ 09.

 

(at Devoxx)

The recently released Portal Pack 2.0 has a new feature called Eventing StoryBoard.The Eventing StoryBoard feature in Portal Pack 2.0 simplifies the task of creating portlet application that uses JSR-286 eventing. It provides a simple drag drop feature to link the portlets involved in eventing. Automatic code generation functionality in the storyboard adds the necessary interfaces, methods and xml elements needed during eventing.

Here’s a tutorial  contributed by Sriram K,  which explains about JSR 286 eventing using Eventing StoryBoard

 http://portalpack.netbeans.org/tutorials/eventing/EventingStoryBoardTutorial.html

There is also a screencast available for the same. Thanks to Hemadri, Anjana, Sriram for their help for this screencast

http://portalpack.netbeans.org/demos/evtstoryboard/eventing-story-board.htm 


http://blogs.sun.com/satya/resource/jsf-small.PNG         A new plug-in called "Visual Portlet Builder" has been added to the recently released Portal Pack Beta 3 plug-ins list. Sometime back I had written a blog entry on how to create a JSF based portlet using NetBeans 6 + Portal Pack through some manual steps. This new plug-in eliminates all those manual steps and provides JSF portlet building capability inside Netbeans. It uses the existing VisualWeb’s WYSWYG editor and enables portlet developers to design their JSF portlet through drag & drop components. You can use OpenPortal Portlet Container 2.0 RC1 to test your jsf based portlets.

Steps to create a JSF Portlet :

  • Create a Web Application with "Portlet Support" framework.
  • Right click on the project node, select New > Visual Web JSF Portlet Page
  • Enter page detail and press Finish.
  • Now you can drag & drop jsf components and design your jsf portlet page.
  • You can create more than one jsf portlet pages in the project and set them as VIEW/EDIT/HELP mode page for the jsf portlet.

To select jsf portlet pages for different modes of the portlet

  • Right click on the visual web jsf portlet page.
  • Select "Set as Initial" and select VIEW/EDIT/HEP mode page

Now you can build and deploy your project on OpenPortal Portlet Container from your NetBeans IDE.

The Portal Pack Beta 3 plug-ins are now available on both Portal Pack project site and NetBeans Beta Auto Update Center.


In Portal Pack Plug-ins, earlier Velocity template engine was used for all type of code generations and templating. But after going through some NetBeans doc I found that NetBeans 6 (Currently under development) bundles FreeMarker template engine with it. But FreeMarker apis are not exposed directly rather those can be used through JSR 223 Library Integration (JSR223: Scripting for Java Platform) in NetBeans.

You can follow the below steps for a easy migration from Velocity to Freemarker template engine in your module

  • Convert all your velocity templates to equivalent Freemarker templates. There is a command line utility to convert velocity templates to Freemarker templates automatically. For more details click here.
  • Change your module’s layer.xml as below to mention the "javax.script.ScriptEngine" attributes as "freemarker" for your template.

                            <folder name="mytemplatefolder">
                                  <folder name="templates">
                                         <file name="mytemplate.java" url="nbresloc:templates/mytemplate.template">
                                            <attr name="position" intvalue="0"/>
                                            <attr name="javax.script.ScriptEngine" stringvalue="freemarker"/>
                                        </file>
                                  </folder>
                            </folder>

  • Add JSR 223 Integration to Module Dependencies
  •  To get the template FileObject  add/use following two methods in your module’s code

                      public static FileObject getTemplateFile(String name) {
                            FileObject fo = getFolder() != null ? getFolder().getFileObject(name) : null;
                            return fo;
                      }

                      public static FileObject getFolder() {
                            if (folder == null) {
                                folder = Repository.getDefault().getDefaultFileSystem().findResource(templateFolder);
                            }
                            return folder;
                    }

         In the above example templateFolder value should be "mytemplatefolder/templates"

  •  Call following method on template FileObject to merge and create the new file

            public final DataObject createFromTemplate(DataFolder f, String name, Map  parameters)

  • You can also directly use the JSR 223 API for template processing and merging

ranjansatya.wordpress.comresource.jpg Recently the JSR 286 draft was available for public review which can be downloaded from this link. It includes some of  the major features which were missed in the JSR 168 spec. You can visit Deepak’s blog to  get a list  of  all those major changes.  One of the major feature introduced  in this  new Portlet  specification is “Resource Serving”  .  In this blog I will  explain  this  feature in detail.

In one line “The resource serving feature provides the ability for a portlet to serve a resource”.

Why it is needed ?

Direct links to the resources in the same portlet web application  are not guaranteed to pass through the portal server and will not have portlet context available. So direct link should be used for the use case where access to the portlet context and access through portal server is not needed.

But the resource url link points back to the portlet. A new interface “ResourceServingPortlet” is introduced in the JSR 286 spec. Via these resource url links serveResource method of ResourceServingPortlet interface is called and portlet can serve the resource which may be protected by the portal security and can leverage portlet context. Portlet container does not render any output in addition to the content returned by the serveResource call. Thus this new life cycle method serveResource() provides more
control to the portlet developer by giving access to write directly on the response object where portal server just acts as a proxy.

The serveResource call can also be used to implement AJAX use cases by invoking resourceURL through XMLHttpRequest in client side javascript. The client side code of the portlet is then responsible for inserting either the markup or otherwise update the page DOM in a non disruptive manner for the other components on the page.

How to Create a Resource URL ?

A resource url can be generated by invoking createResourceURL() method of the RenderResponse object  in render phase of the portlet or doView() method of the Generic Portlet.

The resouce url can also be created inside serveResource() method of the ResourceServingPortlet. In that case portlet developers need to call createResourceURL() method on ResouceResponse object passed to the serveResource() method.

In the following code snippet we will create a resource url inside the doView() and then we will set that url as a IMG source in the rendered output.

public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {

response.setContentType(“text/html”);
PrintWriter writer = response.getWriter();

ResourceURL resURL = response.createResourceURL();
resURL.setResourceID(“image”);
writer.println(“<IMG src=\”” + resURL+ “\” >”);

//Render other markups

}

So when the browser loads the portal page to show the view mode of the portlet, it automatically sends the request for the resURL which goes through portal and finally serveResouce() of  GenericPortlet is called to serve the resource (in this case “image”).

The serveResource() for this example should look like below

public void serveResource(ResourceRequest resRequest, ResourceResponse resResp) throws PortletException, IOException {

resResp.setContentType(“image/png”);
byte[] b = getImage(“MyImage.PNG”);  //Returns image bytes
resResp.getPortletOutputStream().write(b);

}

I have taken the above image example to explain the usefulness of this new feature properly. But  you may also want to create a link for a resource url in your doView() and then on clicking on that link, serverResource() will be called which will only show the output returned from the serveResource().

You can also set a resource id of the resourceURL to enable same serveResource() serving multiple resources. You can also create new resource urls inside serveResource().

The cache level of a resource url can be set through setCacheability() of ResourceURL class though there are certain restrictions in setting cache level. Possible values are: FULL, PORTLET
or PAGE. This helps for Caching of Resouces. To know more about caching in JSR 286 check Karthik’s blog.

You can check out the sources of OpenPortal Portlet Container which has the implementation for serve resource feature of JSR 286. Try it out.

In this blog I will explain how  NetBeans 6.0 M10 with Visual Web Pack and Portal Pack 2.0 preview plug-in can be used to develop & deploy JSF Portlet application.

NetBeans Portal Pack : As a plug-in for NetBeans IDE, it provides supports to create JSR-168 portlet. It also supports deployment of portlets on OpenPortal Portlet Container & OpenPortal Portal Server from NetBeans IDE.

NetBeans Visual Web Pack : Using Visual Web Pack user can Drag and drop JavaServer Faces components and design JSF based web application. But currently there is no support for portlet application.

Sun Java Studio Creator 2 : It provides all the functionalities of Visual Web Pack . Also it provides supports for JSF portlet creation through drag and drop of  JSF components.

In future NetBeans Visual Web Pack will be the full replacement for Sun Java Studio Creator and everything supported by Sun Java Studio Creator will be supported by NetBeans with Visual Web Pack.

Currently the JSF Portlet Builder capability is missing in the current version of Visual Web Pack. So for last few days I was trying to make NetBeans Portal Pack and Visual Web Pack working together and provide JSF Portlet Builder functionality through Visual Web Pack and deployment functionalities through NetBeans Portal Pack. Finally I found some manual steps to achieve this functionality and believe me it’s worth following those workarounds.

Installation and Configuration Steps :

  1. Download and Install NetBeans 6.0 M10 with Visual Web Pack
  2. Download and Install NetBeans Portal Pack 2.0 preview for NetBeans 6.0 M10 .
  3. Follow the instructions given in http://blogs.sun.com/satya/entry/easy_steps_to_set_up   to setup GlassFish Application Server & OpenPortal Portlet Container. No need to install GlassFish App Server separately if you have already installed it during NetBeans IDE installation.
  4. To know how to configure OpenPortal Portlet Container in your NetBeans IDE go through this user guide.
  5. Add Javaee.jar to your run time server instance classpath in NetBeans IDE . This is a one time process which is required for compilation of jsf portlet projects.(But this step will not be required in the future version of the Portal Pack and javaee.jar will be added automatically.) To do this
  • Go to Services > Servers
  • Right click on the "OpenPortal Portlet Container" instance
  • Server Config dialog box opens
  • Click on "Classes" tab for OpenPortal Portlet Container .
  • Add Javaee.jar which can be found at glassfish_home/lib/javaee.jar .
  • Press "Apply" button to save this change
  • Please restart the NetBeans IDE to make sure that server instance classpath is refreshed

Steps To Create JSF Portlet Application :

  • Create a New Web Project. Select "Visual Web JavaServer Faces" framework during project creation to create a JSF based web application. Don’t select "Portlet Support" framework during project creation.
  • After the project is created, add "Portlet Support" framework to that project. To do that
    • Right click on the project node
    • Click on Properties > Frameworks
    • Click Add to add "Portlet Support" framework to this web application.
  • Now configure your project to package jsf-portlet.jar into the final war file. Don’t add this jar to the project’s library or classpath. To set the packaging option
    • Right click on the project node
    • Click on Properties
    • Select "Packaging" under "Build" node.
    • Press "Add File/Folder" button
    • Select downloaded jsf-portlet.jar . Enter "Path In War"  as "WEB-INF/lib" to package and make this jar available during runtime of  this web application.
  • Open web.xml and comment out the following <init-param> section in the  FacesServlet declaration.

                   <init-param>
                                <param-name>javax.faces.LIFECYCLE_ID</param-name>
                                <param-value>com.sun.faces.lifecycle.PARTIAL</param-value>
                   </init-param>

  • Notice by default there is a Page1.jsp file created inside that web application.
  • Now open portlet.xml created under WEB-INF folder. Add following xml elemet to your portlet.xml

<portlet>
        <description>JSF Sample Portlet</description>
        <portlet-name>jsfsampleportlet</portlet-name>
        <display-name>JSF Sample Portlet</display-name>
        <portlet-class>com.sun.faces.portlet.FacesPortlet</portlet-class>
        <init-param>
              <description>Portlet init view page</description>
              <name>com.sun.faces.portlet.INIT_VIEW</name>
              <value>/Page1.jsp</value>
        </init-param>
        <supports>
              <mime-type>text/html</mime-type>
              <portlet-mode>VIEW</portlet-mode>
              <portlet-mode>EDIT</portlet-mode>
              <portlet-mode>HELP</portlet-mode>
        </supports>
        <portlet-info>
              <title>JSF Sample Portlet</title>
              <short-title>jsfsampleportlet</short-title>
        </portlet-info>
  </portlet>

   Note that Portlet INIT_VIEW page is set as Page1.jsp . You can set it to any custom page if you want
. Now your deployment descriptor is ready for deployment.

  • Now double click on the Page1.jsp to open the jsf visual editor for this jsp.
  • Go to "JSP" mode in that visual editor which shows the code for the jsp.
  • Add <div style="-rave-layout: grid; position: relative; height: 400px;">  element just after <f:view> element as an sub-element of <f:view> . Make sure to end that </div> just before </f:view> in the end. So the JSP code will look like something below. This is required to make sure that all markup of jsp page will be shown inside that portlet window and ignore any absolute location.

                          …….  

                         <f:view>
                            <div style="-rave-layout: grid; position: relative; height: 400px;">
                            <webuijsf:page binding="#{Page1.page1}" id="page1">

                            …..

  • Add <webuijsf:themeLinks ajaxify="false" id="theme_1"/> element just after <webuijsf:body> element  but before <webuijsf:form> element as an sub-element of <webuijsf:body> . This  ThemeLinks component is used to create references to theme resources on
    a page in a portlet environment, where the Head component cannot be used. After this change the JSP code will look like below

                ……
                <webuijsf:body binding="#{Page1.body1}" id="body1" style="-rave-layout: grid">
                        <webuijsf:themeLinks ajaxify="false" id="theme_1"/>
                        <webuijsf:form binding="#{Page1.form1}" id="form1">

                …….

  • Now save that JSP
  • Go to "Design" view
  • Open the Palette for this JSF designer and drag and drop components to the designer to design your JSF page.
  • After you done, save your JSP

To Deploy the Application

  • Select the target run time for this web application as an instance of "OpenPortal Portlet Container"
  • Then right click on the project select "Undeploy and Deploy" to deploy this application as portlet application on OpenPortal Portlet Container.

I usually hate long blogs 🙂 So I am summarizing above contents

  • Download, install and configure all required components
  • Add javaee.jar to server instance classpath which is required for compilation.
  • Create a Visual Web Application
  • Add "Portlet Support" framework
  • Add jsfportlet.jar for packaging
  • Comment out the <init-param> section for FacesServlet in web.xml
  • Add jsf portlet entry to the portlet.xml
  • Add <div> and <webuijsf:themeLinks> tag to jsp code
  • Design using drap & drop support
  • Deploy your application to portlet container.

In case any issue, please leave a comment.