|
|
Portlet Java2 En
article of MassimilianoDessi
translated by Nelly Cannas ( nellycannas[#at*]yahoo[*dot#]it ) Portlet II Introduction In the previous article we have seen in a general way the features of portlets and of a open-source portlet Container: Jetspeed. We have seen how pages are built through Velocity templates (or Jsp) and psml files, which call the portlets. Let's continue seeing portlets' hierarchy, base classes' behaviours, which we have to use for the different tasks, how to write them and how to deploy. We will refer to the last release available now: Jetspeed 1.4b4. This version will probably be the last but one in beta version before the release of Jetspeed2, that will be compliant to the specifics of java community process for portlets [1]. Portlet hierarchy To understand well some projectual choices that we can found in some Jetspeed's classes we have to go up to the period when Jetspeed was born, when information canal meant the visualization of static contents, web-applications had just born. The idea of portlets , was justified from the necessity of centralizing information in one only portal. So some kinds of portlets used then can seem now obsolete. On the contrary, others that were recently introducted use the modern standard of programmation and architecture, they use MVC paradigm. To confirm this statement let's see the interface of portlet that were firstly introduced that we can find in the package: org.apache.jetspeed.portal.portlet it has stayed the same since the version 1.3a1. ![]() Portlet interface The methods that it exposes are those used to show contents, to set attributes, but they don't allow to make elaborations. The main method in this interface is the getContent() that returns html through an org.apache.ecs.ConcreteElement [2]ECS (element construction set) is a Jakarta Project that permits the composition of html tags by means of java objects. If we had needed to use a portlet of this kind, the html file that would have been visualized should have been composed line after line with StringElement inside a code making the modification of the presentation complicated. A class that implements this interface is: org.apache.jetspeed.portal.portlets.AbstractPortlet that is the generic class containing the generic functionalities of portlets. ![]() AbstractPortlet In this portlet we have the same methods of the portlet interface and some other more that are necessary to identificate the portlets through an id, to set decorations and labels for the portlet, but we don't have real elaborations. With the passing of time and the affirmation of servlets and of framework, that allow to support the MVC paradigm, we arrived to the actual situation. In the actual version 1.4b4 (b means beta version) we have package like: org.apache.jetspeed.portal.portlets.GenericMVCPortlet that consents the interaction of a user with a portlet behind which there is an application that answers to the input of the user. A portlet of this kind works with a Velocity o Jsp template used as View, the action called in the request used as Controller, and the Model are the data put by the action in the context of Velocity, that shows them through the templates. The use of the actions is allowed by the class org.apache.turbine.modules.action, that permits us to write actions, that will be executed by Turbine when they are asked in the url. In this way we will be able to write a portlet that extends an action or a VelocityPortletAction. In the current version the JspAction and VelocityAction are abstract classes and they extend the class :org.apache.jetspeed.modules.actions.GenericMVCAction In this way in the method doXXX will be put the logic used as a Controller. ![]() GenericMVCPortlet Now let's see an example
Once we have compiled it and put it in one of the directories, classes or packaged in a jar into lib, it is necessary a descriptor like deployment descriptor for the ejb. For the portlets too it is an xml file with xreg extension. In the xreg file we write: · The entry name that we will see called in the psml file associated to the user. · The title and the decription that will be visualized in the pages where we choose the portlets. · Name of the template .vm associated (maxx.vm) · The name of the class that contains the action(s) (portlets.MAXXAction) · The media-type · Category group . In the maxx.xreg: In the maxx.vm We will have access to the object put in the context with the put() method. With this example we have seen how with a VelocityPortlet (o JspPortlet) it is possibile to realize applications that make different tasks and different actions according to the parameters with which they are called, (in the example doUpdate). Once we have put the vm template into the directory WEB-INF/templates/vm/portlets/html , we must put the xreg file into the directory WEB-INF/conf/ or copy into another xreg file the text between the tags <portlet -entry> and </portlet-entry> included. A service of Jetspeed that reads the xml file of configuration at regular intervals of time will read our add hot-plug. The name of this service and the interval of time are written in a properties file of Jetspeed. The authenticated user who wants to change his pages will find in the list of the available portlets the portlet that we have just seen. ![]() List of Portlets ![]() Final result Once we have put the portlet in the pages , the portlet with an id created by Jetspeed will be put int the psml file , that can even be in a database. The id is necessary because the istance of the portlet works like a servlet that can satisfact many contemporary requests, but the portlet must even distinguish the different clients that call her and could need different configurations. Jetspeed will even make the caching of the output of the portlets to satisfact faster the requests. Conclusions In this second article we have seen the most common portlets: The abstract portlet firstly used to visualized static contents, and the more recent ones, that are MVC portlet (VelocityAction and JspAction), and allow to make elaborations through the actions. These two kinds of MVC portlet are the best ones to integrate applications through portlets. In the next artiche we will see what the Java Community Process has written about portlets. Bibliography and references Jetspeed: Enterprise Information Portal :http://jakarta.apache.org/jetspeed Turbine: Web Application framework :http://jakarta.apache.org/turbine Velocity: Java Template Engine: http://jakarta.apache.org/velocity [1]jsr168: http://www.jcp.org/en/jsr/detail?id=168 [2] ECS Element construction set :http://jakarta.apache.org/ecs/ src MassimilianoDessì (desmax74[*](\)@(/)[*]yahoo[*](/).(\)[*]it) He has started working at the Sistemi Informativi S.p.A (IBM) (http://www.sistinf.it) as a Java programmer. Since 2001 he has been working at the Atlantis S.p.A. (http://www.gruppoatlantis.com/), where he uses agile methodologies as the eXtreme programming (Xp), he develops enterprise Web-based applications with J2EE technology, like portals and content management system for territorial promotion. In his free time he co- operates to the open-source Jakarta –Jetspeed project, and he takes care of the Italian version of Jetspeed. He studies electronic engineering at the University of Cagliari. |