File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Portals and Portlets and the fly likes More than one portlets in a single war file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Portals and Portlets
Bookmark "More than one portlets in a single war file" Watch "More than one portlets in a single war file" New topic
Author

More than one portlets in a single war file

Dorothy Taylor
Ranch Hand

Joined: Nov 26, 2007
Posts: 104
Hi All

Can anyone please tell me when do we need to package more than one portlets in the same war file?

Thanks in advance
Hemant Sharma
Greenhorn

Joined: Feb 01, 2007
Posts: 23
More than one portlets are packaged in the same war
- When we have related portlets which need to share the same context which
contains all resources such as images, properties files and classes.
- Theres a need to share resources and send messages among the portlets to communicate events.


Thanks & Regards,<br />Hemant K. Sharma
Dorothy Taylor
Ranch Hand

Joined: Nov 26, 2007
Posts: 104
And what if two portlets have the same JSP or the formbean? In this case also do they need to be in the same war file
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Yes, if two portlets have the same JSP, they need to be in the same war, that's for sure.

A single portlet application is delivered as a war file, but that application may have many portlets within it. An accounting application might have one portlet that allows you to file, one that allows you to find tax information, one that allows you to manage receipts, and anothet that allows you to file income. All might be different portlets, but packaged together in a common war file.

Many tutorials show only one portlet per war, but when you get deep into portlet programming, many portlets per war becomes the norm.

-Cameron McKenzie
Jonas X. Yuan
author
Ranch Hand

Joined: May 18, 2008
Posts: 108
Hi

here is an example - one war, five portlets. - Spring MVC portlets in Liferay

1. Download plugins-sdk with Spring MVC portlets from http://liferay.cignex.com/sesame/plugins-sdk.zip
2. Unzip plugins-sdk.zip; Find build.Jonas.properties
3. Rename build.Jonas.properties into build.${username}.properties.
4. Update entry (app.server.dir) in build.${username}.properties. Let it point to Liferay Tomcat directory. For example: app.server.dir=C:/training/tomcat.
5. Drop �build.xml� at /portlets to Ant view.
6. Development �
7. Run Deploy at Ant view if you are ready.
8. Test portlets at Liferay runtime �


Books: Liferay Portal 6.1 Systems Development
Dorothy Taylor
Ranch Hand

Joined: Nov 26, 2007
Posts: 104
Originally posted by Cameron Wallace McKenzie:
Yes, if two portlets have the same JSP, they need to be in the same war, that's for sure.

A single portlet application is delivered as a war file, but that application may have many portlets within it. An accounting application might have one portlet that allows you to file, one that allows you to find tax information, one that allows you to manage receipts, and anothet that allows you to file income. All might be different portlets, but packaged together in a common war file.

Many tutorials show only one portlet per war, but when you get deep into portlet programming, many portlets per war becomes the norm.

-Cameron McKenzie



In this example, why do we need to package all these accounting portlets in a single war? Why can they not be independent portlets?
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

As I always say, there are no right answers, only wrong answers. As long as we don't get a wrong answer, we are okay.

A war should contain a set of common, related components - just like in a large Servlet & JSP application. If you have a bunch of HR or Accounting portlets, it makes sense to deploy them in a single war. Furthermore, being in a single war makes it possible to have then share information through the PortletSession's application scope.

If you have IBM portal, look at all the portlets IBM provides that are in a common, single, war. I think Lotus Notes has like 10 portles that provide Notes functionality, all of which are sensibly packaged in a single war. After all, it' be annoying to have to deploy 10 war files to get 10 commonly related portlets that provide Notes functionality.

-Cameron McKenzie
Dorothy Taylor
Ranch Hand

Joined: Nov 26, 2007
Posts: 104
ok, understood that, but just one more small query...as you said that similar portlets can be grouped as a single war. Now, how should the implementation be for the action classes and jsp's of such portlets? I mean even when the portlets are packaged in one war, should they have independent action classes and jsp's unless they are absolutely alike, or should we check in the SAME action class if portlet "A" triggers this action do something and if portlet "B" triggers then do something else
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Even though they might be packaged together, you can still develop them as though they were independent portlets.

It becomes simliar to a Servlet/JSP application in that regard. If you have a LoginServlet that forwards to a successfullogin.jsp page, that Servlet and JSP page doesn't need any knowlege of a Servlet named GetAccounBalance or a JSP named displaybalance.jsp.

They may be in the same war file, and even the same folders, but they need not interact with each other. In that regards, the portlets become similar to Servlet and JSPs packaged in a common war.

-Cameron McKenzie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: More than one portlets in a single war file