Default style (Cherry Eve). Switch styles (Capricorn). Atom Feed Calendar
http://blogs.sun.com/patriceg/date/20070212 Monday February 12, 2007

Ajax-ing / jMaki-ing JSR168 Portlet for JES-Portal - Part 2

Last update : 14 Feb 2007 

This blog is the second in a series on How-to develop/deploy JSR168 Portlet for Java ES-Portal.


  1. The previous article ( Part 1 :
    How to develop/deploy SAP JSR168 Portlet for JES-Portal
    ) enlightened the development environment recommended to create/test/deploy easily JSR168 portlet.
  2. This article (Part 2: Ajax-ing / jMaki-ing JSR168 Portlet for JES-Portal)  will focus mainly on the added values provided by AJAX/jMaki widgets.

 1. What have we done so far?  

In the previous article, we have developed a SAP NameFinder JSR168 portlet with a traditional approach that is to say without any AJAX/jMaki widgets.

Behind the scene, the JSR168 portlet is composed of a servlet and 3 JSP pages : view, edit & help pages. The servlet acts as a Controller of a typical MVC model sending a request to SAP, getting in return a huge SAP structures to be displayed in the view.jsp.

2. What is the main concern of this traditional approach ?
Nothing except I don't like coding when I can pratice scubba diving .... 

As far as the presentation layer is concerned, a great part of the code written for this sample is embedded into the view.jsp.  Browsing this screenshot, it can be noticed some fancies features have been integrated such as a « sorting » mechanism for each column. When you want to implement this sorting mechanism you need a couple of Java statements. Right???

The JSP able to handle this sorting mechanism is about 600 lines of HTML tags + Java statements.

 3. jMaki widget an easy way

Important Note :

YOU HAVE TO  use the Netbeans-jMaki plugin version 1.6.9 or later.

Module Manager for Ajax Module in Netbeans  


 

Let see how a jMaki widgets can be helpful in this direction. A couple of jMaki widgets can be used as a Dojo Table or a Dojo eTable. Let take the simple one : a Dojo Table.

We got the following results :

 

In order to make use of a Dojo Table in this sample, we have to :

  1. create a  Bean in order to xform the SAP returned data into a JSON Array
  2. remove from the view.JSP the Table and all the code required to sort each column
  3. insert a Dojo Table in the view.jsp
  4. pass to the Dojo Table a JSON string managed by a session bean with the SAP data to be displayed.

4. So what / Conclusion

  • The GUI design is more or less the same,
  • With the  jMaki  version, the column sorting mechanism comes for free : we don't code a single line about this stuff.

About the standard implementation 

The initial JSP is about 600 lines of HTML tags and Java statements. A great part of this JSP code is dedicated the sorting mechanism of the columns. We are talking about 350 lines wrtitten to manage the columns sorting

About the jMaki implementation 

The 350 lines have been remplaced by the following jMaki tag and a Java Bean in charge of the xform of the SAP returned data in a JSONArray to be consumed by the jMaki tag

 Sample code required for sorting a column  : X  7 as we have 7 columns
 jMaki tag
         <!-- Start Employee Number header and Arrow -->     
        <th align="left" class="TblColHdr" scope="col">
        <table class="TblHdrTbl" border="0" cellspacing="0" cellpadding="0">
          <% if(sortField==NamefinderDetailComparator.SORT_FIELD_EMP_NUMBER && sortOrder==NamefinderDetailComparator.SORT_ORDER_DESCENDING){ %>
          <tbody>
            <tr>
              <td><a href='<portlet:actionURL>
                       <portlet:param name="operation" value="SORT" />
                   <portlet:param name="sort_field" value="EMP_NUM" />
                   <portlet:param name="sort_order" value="ASC" />
                   </portlet:actionURL>' class="TblHdrLnk"
                            title='<fmt:message key="SORT_ASCENDING"/>'><fmt:message key="NAMEFINDER_RESULT_EMPNUMBER"/>
                   </a>
              </td>
              <td><a href='<portlet:actionURL>
                       <portlet:param name="operation" value="SORT" />
                   <portlet:param name="sort_field" value="EMP_NUM" />
                   <portlet:param name="sort_order" value="ASC" />
                   </portlet:actionURL>' class="TblHdrLnk"
                            title='<fmt:message key="SORT_ASCENDING"/>'>
                            <img src="<%=renderResponse.encodeURL(renderRequest.getContextPath()+"/images/table/sort_down_sel.gif";)%>" alt='<fmt:message key="SORT_ASCENDING"/>' width="27" height="13" border="0" align="top">
                   </a>
              </td>
            </tr>
          </tbody>      
          <% }else{ %>
            <tbody>
            <tr>
              <td><a href='<portlet:actionURL>
                       <portlet:param name="operation" value="SORT" />
                   <portlet:param name="sort_field" value="EMP_NUM" />
                   <portlet:param name="sort_order" value="DSC" />
                   </portlet:actionURL>' class="TblHdrLnk"
                            title='<fmt:message key="SORT_DESCENDING"/>'><fmt:message key="NAMEFINDER_RESULT_EMPNUMBER"/>
                   </a>
              </td>
              <td><a href='<portlet:actionURL>
                       <portlet:param name="operation" value="SORT" />
                   <portlet:param name="sort_field" value="EMP_NUM" />
                   <portlet:param name="sort_order" value="DSC" />
                   </portlet:actionURL>' class="TblHdrLnk"
                            title='<fmt:message key="SORT_DESCENDING"/>'>
                            <img src="<%=renderResponse.encodeURL(renderRequest.getContextPath()+"/images/table/sort_up_sel.gif";)%>" alt='<fmt:message key="SORT_DESCENDING"/>' width="27" height="13" border="0" align="top">                           
                   </a>
              </td>
            </tr>
          </tbody>
          <%}%>
        </table>
        </th>
        <!-- End Employee Number header and Arrow -->     
 <a:ajax name="dojo.table"
                    value="{columns:
                    { 'employeenumber' : 'EmployeeNumber #', 'firstname' : 'FirstName', 'lastname' : 'LastName',
                       'roomnumber' : 'RoomNumber', 'building' : 'BuildingNumber', 'extension' : 'Extension',
                       'email' : 'eMail'},
                    rows:${appBean.namefinderdetail} }" />

It is up to you


 

Comments:

I am trying to get jMaki to work within my JSR-168 portlet (using JSP, not JSF) and it is not working. I used the Netbeans jMaki plugin, setup a new web application, and made sure that worked. I then copied the resources directory over to my existing portlet project, added the jMaki library, and added a jMaki component to my JSP. When I run the portlet it fails with a NullPointerException. Is there any special setup needed make jMaki work in a portlet?

Posted by Michael on February 14, 2007 at 09:45 PM CET #

Michael, You definitively need to get the latest NB55 plugin. I got the same issue before. You can download this plug-in from https://ajax.dev.java.net/servlets/ProjectDocumentList?folderID=6844 Let me know Patrice

Posted by Patrice on February 14, 2007 at 10:00 PM CET #

You were correct. I just finished downloading the jMaki wrapper jar and testing it and it worked! I am going to install the latest NB55 plugin now.

Posted by Michael on February 14, 2007 at 11:07 PM CET #

I'm also having problems using jMaki in a JSR-168 portlet created in Netbeans. Have to add that I'm using Netbeans 6.0M9, and tries to deploy the portlet to a JBoss Portal 2.6CR2. I'm getting a NullPointerException in AjaxContext.java line 107. I have installed the 1.6.9.9.1 version of the netbeans plugin, running on jdk1.5.0_08 Thanks in advance..

Posted by Viggo Navarsete on June 15, 2007 at 04:11 PM CEST #

asdfasdf

Posted by 189.5.72.11 on June 22, 2007 at 04:11 AM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed