This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Portals and Portlets and the fly likes How should Portlets fit in MVC? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Portals and Portlets
Bookmark "How should Portlets fit in MVC?" Watch "How should Portlets fit in MVC?" New topic
Author

How should Portlets fit in MVC?

John King
Ranch Hand

Joined: Aug 27, 2002
Posts: 165
I see Portlets should act as Controller (just like Servlets) and JSPs act as View. So no HTML markup should be presented in Portlets' doView, doHelp, or
doEdit. Any comments?
Stefan Zoerner
Author
Ranch Hand

Joined: Nov 29, 2001
Posts: 121
John,

long comment:

The portlet markup must be created in the render phase of a portlet's life cycle, which is represented by the render method of interface javax.portlet.Portlet. doView, doEdit etc. are methods of GenericPortlet, which is an adapter class of the Portlet interface. The render method dispatches to them.
It is not forbidden (and quite common for simple examples) to produce HTML markup during the render call, e.g. in the doView method. JSP is one option to create the markup (you may choose other technologies like tapestry or JSF) during the render call. In this case, your markup is in the JSP file, and the render (or doView) call includes its output with a PortletRequestDipatcher. The data presented by the JSP (Java objects) is created before the include call in the render phase or during processAction (two options here).

short comment:
we do it just as you have described it

Greetings, Stefan


Stefan Zoerner
Author of German LDAP-Book
Committer at Apache Directory Project
John King
Ranch Hand

Joined: Aug 27, 2002
Posts: 165
Stefan, I saw you are a IBM certified Portal developer so am asking another
question:

How should Struts fit in Portal/Portlet? Which component is the Controller?
Stefan Zoerner
Author
Ranch Hand

Joined: Nov 29, 2001
Posts: 121
John,

Struts and most other web frameworks do not exactly fit to the portlet paradigm, because in JSR 168 we have two types of requests (render, action), in the Servlet API (and Struts etc.) there is only one. But the basic ideas are comparable.

The portlet class itself acts as a controller (just like the ActionServlet in traditional Struts). You may program actions/commands as pojos and call them from the lifecycle methods of the Portlet class. Not that both render() and processAction() may perform a command, it depends on your situation which one is right. After that you dispatch to a JSP or use another template techology to create the markup.

You can create your own framework for that, but some already exist. There are also bridges available for Struts, but they hide the portlet paradigm -- I would only use them to cahnge an existing Struts app into a portlet, if you do not have the time to do it right ;-)

Links:

MVCPortlet
Spring Portlet MVC
Struts Bridge (Apache Portals)
[ January 05, 2006: Message edited by: Stefan Zoerner ]
John King
Ranch Hand

Joined: Aug 27, 2002
Posts: 165
Stefan,

Thanks for your comments on Struts and Portlets.

I was told that it is very easy to convert a Struts application to
Portal/Portlet application. It is not true from what I read:

All the Action classes and JSPs need changed. If alots of JavaScripts
are used in JSPs, there will be more problems ....

A question:
What is "service portlet" and "business process portlet"? They are not in
JSR168. I guess these portlets do not create any HTML markups. Why do we need them instead of EJB or Web services?
Stefan Zoerner
Author
Ranch Hand

Joined: Nov 29, 2001
Posts: 121
Hello,

"business process portlet" seems to be a vendor specific term (IBM, WebSphere Portal in conjunction with WebSphere Process Server). Check out this article. But these portlets will generate markup (HTML, WML, ...) just as other portlets do. Just a web (portal) based frontend for human interactions which are controlled by a workflow engine.

WebSphere Portal supports "portlet services", but I have no idea what a "service portlet" is. Where did you find this term?

Greetings,
Stefan
[ January 09, 2006: Message edited by: Stefan Zoerner ]
John King
Ranch Hand

Joined: Aug 27, 2002
Posts: 165
Sorry. It should be called "portlet service".
Neeraj Shidhaye
Greenhorn

Joined: Jan 09, 2006
Posts: 8
Hi,

For MVC Portlet Developement , u can refere the following article

http://today.java.net/pub/a/today/2005/03/08/mvcportlet.html

nJoy
~Neeraj Sidhaye
try_catch_finally@yahoo.com
http://www.extremeportal.blog.co.uk
Stefan Zoerner
Author
Ranch Hand

Joined: Nov 29, 2001
Posts: 121
John,

portlet services are vendor specific (IBM WebSphere Portal). Learn more about them in chapter 19 of this redbook (complete content available online in PDF and HTML).

The most useful predefined portlet service from my point of view is "Credential Vault Service", which allows you to access the crendential vault of portal server.

Greetings, Stefan
John King
Ranch Hand

Joined: Aug 27, 2002
Posts: 165
Stefan,

I'm reading the redbook. The "portlet service" is more like a Proxy on the client side to the backend service. The call from portlet to portlet services are local in the same Portal server. So it can not replace RMI or EJB.

Portlet service is a shared service by other portlets. But, like all the lib, it can be done with a simple jar file.

Why does IBM require us to register it?
 
GeeCON Prague 2014
 
subject: How should Portlets fit in MVC?