Portlet development framework

Source: Internet
Author: User

Original article: http://www.ja-sig.org/wiki/display/UPC/Portlet+Development+Framework

I spent a few weeks researching different approaches and frameworks to developing portlets. the basis for this research was to find a good methodology to developing portlets for uportal 3.0. A specific desire was to try to find a way to reuse as much functionality as possible using SS different portlets.

Portlets are different from uportal channels. uportal channels are not an industry standard. portlets are different from servlets. portlets and servlets are both industry standards, but portlets may not assume complete ownership of the web page they are presented in.

Using frameworks exist for servlet application development. however, most of these frameworks do not account for the fundamental differences that are inherent to a Portlet. consequently most servlet based frameworks either do not work, or work, with repeated restrictions and hacks put in place.

The following frameworks were investigated.

  • Struts
  • Spring
  • Mvcportlet
  • Assumerver faces

Mvcportlet

Let me start off with mvcportlet. this framework was built by NaBH Information Systems, Inc (http://www.nabh.com /). it is the only framework that was built with portlets in mind. the Framework is available as open source, but appears to be tightly controlled by NaBH. the website itself had a strange feel to it, during navigation (appears cookies, may have tracked which pages you were on, rendering the standard back/forward buttons useless ). the framework appears like your others to be based on Using JSP pages for a "View" technology and providing a framework of Java code for helping write the back-end logic. for me, a very significant impression was made by looking at the JSP pages presented in the documentation, and how most everything was done with scriplets. the JSP pages were more 'java' code then they were anything else. it is my recommendation that If JSP pages are used tag libraries shoshould be used as much as possible, scriptlets shocould not be required.

I recommend against using mvcportlet for three reasons. 1) The heavy use of scriplets implies a poor overall design. 2) The framework is still considered beta, and therefore cocould undergo fundamental API changes causing us to have to rewrite code to upgrade to a stable release. 3) There is no past history with the NaBH community to know what the life expectancy of this framework is.

Assumerver faces

In the last year the specified erver faces (JSF) technology has gathered a pretty decent following. JSF 1.0 was created under the Java Community process with JSR-127. since then version 1.1 has been released and version 1.2 is in the works (JSR-252 ). the goal of JSF was to allow people to think about building Web applications in a different way. allow developers to build components and not worry about creating Servlets, pages, or views. the way this is accomplished in a web environment is with the JSF technology owning the servlet that is used and playing a heavy role in the resulting HTML that is sent to the browser. JSP pages seem to be the only popular view technology current available (although the specification allows room for other view technologies to be developed ). JSF has a rich lifecycle that is not entirely compatible with JSPs (see http://www.onjava.com/pub/a/onjava/2004/06/09/jsf.html and comments for more info ). the facelets view technology has been developed to avoid that.

Portlets are not Servlets, and there is a slight problem with having your core application be a JSF servlet. A porlet "add-on" library was written to allow a JSF application to be distributed as A Portlet web application. I was able to take two examples from the JSF reference implementation and get them running as portlets inside of uportal 2.4 + (CVS head on March 21,200 5, they wowouldNotRun in uportal 2.4.2) with this add-on library. my impressions were pretty sub par. the portlets wocould consistently flake out. it was very common to have to logout/login, or stop/start the server, multiple times, with no other changes, to get the portlets to run. another design issue seems to be the idea of the 'beans 'it creates for each user session. there did not appear to be a way to specify any beans as 'reusuable' then ss multiple sessions. this means for every user login every bean configured for this application, must be created. the memory overhead that cocould be associated with this is a concern.Correction: Beans can be specified to have Application Scope

JSF was specified to allow implementations to support portlets (externalcontext is used to wrap either portletcontext or servletcontext ). apache MyFaces now has support for portlets which works fairly well in uportal 2.5.0, but is still a little buggy.

I recommend against using assumerver faces for the following reasons. 1) portlets are not officially supported, and the Portlet-add on library appears unstable in uportal 2.4 +.2) memory cocould be a concern if all beans are always created for all user login sessions and there is no way to reuse a paticular bean into SSS different users sessions.3) It's very different from other Portlet/servlet technologies and cocould be harder for the uportal community to initially support. 4) there is no apparent support for Portlet modes or preferences.Correction: modes can be handled, but not extremely elegantly. See http://wiki.apache.org/myfaces/UsingPortletModes. I believe preferences can be accessed within the methods of MyFaces 'myfacesgenericportlet.

Struts

Struts is a very popular and widely adopted MVC Framework for the web. the current stable version is 1.2.4 and 1.2.6 is currently in Beta. struts is also based on Servlet technology and does not currently directly support portlets. there are currently two proposals for struts 2.0.x (shale and Jericho) and it is not clear what the timeframe is for direct Portlet support.

The Jetspeed-2 portal project developed a library called "portals-brdiges" that can be used to run STRUTS Based applications as portlets. there is a desire to make this library it's own subproject. using the Library requires you to use JSP pages and places numerous restrictions on how you write your struts application. I was never able to successfully pull the 'portals-Bridges' library out of jetspeed-2 and get a sample application running in uportal.

Stuts is very popular and can make creating web applications quicker, by elinimating writing most of the dispatcher logic that is typically writtent with other frameworks. however, there are using opponents to struts as well. regardless, the inability to get any STRUTS Based example running in the time of this research, means it is impossible to consider struts an option for now.

Spring

Spring is component based framework that accomplishes a lot more the just an MVC framework. spring is being used by uportal 3 for non-MVC activities. I researched the MVC aspects that spring current offers. the latest stable release of spring is 1.1.5. version 1.2 of spring was nearing release at the time of this research. and spring 1.3 is intended as the next release after 1.2, with a possible timeframe of summer 2005. one component of spring is called the "Spring web MVC" component, and offers a framework for servlet based Web applications. the released version of spring web MVC does not support portlets. there is code available in the development area of spring (the 'sandbox' directory of the spring cvs repository) that extends spring web MVC for Portlet support. I followed up on the spring mailing lists, the Wiki pages, and obtained and compiled the code.

At the most basic level the spring Portlet support appears to be in the form of the portletcontroller class. you can extend this directly or use one of the convenience classes that extend it for you. one concern I have is the portletcontroller provides you the ability to override two methods. both of these methods are named 'handlerequest 'but are overloaded with different parameter lists. these two methods are roughly equivalent to the 'processaction' and 'render' methods of the Portlet interface. I assume the names were chosen based on extending support from the Web MVC controller class which contains one handlerequest method. however, that does not excuse what is fundamentally poor design. valid JAVA does a good job at describing this situation on page 111. overloading of Methods shocould not be used for two fundamentally different activities. could t for this one poor design choice, I did not find any other notable problems with the Framework. I also did not find a lot of value either. the framework simply does not do very much for you.

I do not currently recommend using spring web MVC for the following reasons. 1) Portlet support is not part of an official release and cocould potentially change before making it into one. changes cocould cause any uportal code to need to be rewritten to upgrade to a more stable version of spring. 2) uportal 3 is currently using spring, however, it is being written to a version that does not include Portlet support. there is a chance the version that wocould include Portlet support might be incompatible with the version that the other uportal code was written. 3) The design choice of calling both the render and action Methods 'handlerequest 'diminishes the significant importance of these two operations.

Tapestry

Tapestry now fully supports portlets. The original author did not consider tapestry in his investigation.

The Code

As part of this research I tried to create an equivalent application in the frameworks I cocould get running. I was able to get a version of the standard number guessing game running under assumerver faces, spring and "no framework ". I was able to convert my "no framework" application to a spring Portlet based example in less then a couple of hours. I made no attempt to go to/from the assumerver faces code, and instead just based my examples on the funcationality provided.

In designing the code for the "no framework" baseline, I tried to come up with a rough framework oriented layout of classes. I created three packages "Web", "Bean" and "action ". the idea was whichever framework was chosen any controller/Portlet/dispatcher style classes wocould go into the "Web" package. the data driven (model) style classes wocould go into the "Bean" package. finally, the "business logic" classes that were responsible for acting on the actual Web driven events wocould go into the "Action" package.

I used JSP pages for a view technology because of the existing Portlet tag library defined by the Portlet specification. I also used the JSP standard tag Library (jstl ). I avoided using any scriptlets In the JSP pages.

You can see the examples in the attached code. each. ZIP file contains a war file that can be deployed in uportal 2.4.2 (or above ). the war file is located in a 'dist' subdirectory for each. ZIP archive. when publishing the Portlet channel in uportal the Portlet definition ID for each example is simply the war filename period war filename (e.g ., the Portlet definition ID for guessnumberportlet. war is guessnumberportlet. guessnumberportlet ). the two JSF examples (jsfguessnumberportlet and jsfcarstoreportlet) will not run in uportal 2.4.2 or 2-4-patches (head of 2.4 branch ). these JSF examples will run in the CVS head (aproximately 2.5) version of uportal. I believe this might have to do with a newer version of Pluto in the head version of uportal CVs.

Recommendation

I recommend not using any existing framework I reviewed at this time. instead coding our portlets with a common dispatcher pattern that can be easily converted to another framework in the future (e.g ., spring Portlet MVC ). I recommend we use JSP pages for view technology to take advantage of the Portlet tag library for handling Portlet URLs within the view page. we can accomplish reusability between portlets we write by using the include mechanisms of JSP pages and writing coresponding backing data beans. this approach leaves uportal as decoupled as possible from frameworks that are still in development, and does not require us spending a large number of hours writing our own framework.

Now with uportal 2.5.0, you shoshould consider JSF, possibly with facelets instead of JSPs.

Future considerations

Although not originally looked at by this research a couple of other projects seem related that shoshould be considered in the future.

Spring web flow and Struts flow are subprojects to their corresponding parent projects. each project appears to also be involved in the larger web application framework picture. in paticular the tiny little bit of exposure I had to spring web flow, by reading the spring mailing list, it appears like it might bring some of the struts like action/state configuration to the srping web MVC. if the spring Portlet MVC is ever released and spring web flow integrates with that, the combination cocould be a significant platform. struts flow appears to allow for more complicated struts application configuration. however by login ue of being a sub project, it might be useable by another Portlet compatible framework, whereas struts itself is not.

Assumerver faces will need to be looked at periodically. with Sakai 1.5 and beyond based on JSF, uportal will need to support JSF. as long as uportal must support JSF, it shocould be considered a viable framework for consideration. the two things to continue to look at here are the stability and memory concerns.

Tiles offers a more robust way to put together web pages. although the technology is roughly equivalent to the include mechanisms of JSP pages it can offer a lot more if a lot of thought goes into setting up the pieces correctly. there is no reason tiles cant be used right away with the approach recommended, this is simply pointing out that to make valid tive use of tiles, wocould require some more time in coming up with the best ways to use it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.