Overview
- Home
- Portlet Concepts
- Portlet Classes
- Portlet TagLib
- JavaDocs
- Portlet DTD
- Download
Writing Portlets
- Hello World
- Portlet with Action
- More examples
Project
- Mailing Lists
- Source Repository
- Issue Tracking
- Project Team
- Road Map
Portlet Catalog
- Basic Portlet
- Bookmarks
- RSS Feed
- Menu
- Login/Logout
- Poll
- Google Search
- Discussion Forum
- Contacts
- Calendar
- Email Client
- Document Manager
Misc.
- Setup jPortlet Project
- Server Side Include
- Internationalization
- Portlet Actions
- Changing Look & Feel
|
Overview
|
When you want do render the content of a portlet, you can output strings into the
PortletResponse
like this:
XPortlet.java |
public class XPortlet
extends PortletAdapter
{
...
protected void doView( PortletRequest request,
PortletResponse response )
throws PortletException,
IOException
{
response.getWriter( ).println( "<p>Hello Fred</p>" );
}
...
}
|
This method is fine, but not the best for complex user interface.
What jPortlet offer is an infrastructure for Server Side Include that allow develloper to
output into the PortletResponse the content of a file located either in the portlet's
classpath of in the portlet's web-module via
PortletAdapter.include()
or
PortletContext.include()
Using Server Side Include, the portlet code look like this:
XPortlet.java |
public class XPortlet
extends PortletAdapter
{
...
protected void doView( PortletRequest request,
PortletResponse response )
throws PortletException,
IOException
{
include( "view.html" );
}
...
}
|
view.html |
<p>
Hello Fred
</p>
|
|
|
Understanding include() function
|
The include() is a very powerful function,
it allows the portlet to render any resource as specified by the given path.
This function also support multi-markup languages and internationalization.
For example, if the portlet com.foo.MyPortlet myportlet
include the resource /mytemplate.html , for a french canadian Mozilla browser,
the portlet container will:
- Detect the client markup language
PortletRequest.getClient()
- Detect the client locale
PortletRequest.getLocale()
- Search the resource from the portlet's classpath (This mean the file is located in the portlet's
.jar )
inside the same package as the portlet.
The container will use the client's markup and locale and search /mytemplate.html
with the following paths:
- com/foo/html/mytemplate_fr_CA.html
- com/foo/html/mytemplate_fr.html
- com/foo/html/mytemplate.html
- com/foo/mytemplate.html
- Search the resource from the portlet's web module
(This mean the file is located in the portlet's
.war )
in a special directory named PORTLET-INF
The container will use the client's markup and locale and search /mytemplate.html
with the following paths:
- PORTLET-INF/myportlet/html/mytemplate_fr_CA.html
- PORTLET-INF/myportlet/html/mytemplate_fr.html
- PORTLET-INF/myportlet/html/mytemplate.html
- PORTLET-INF/myportlet/mytemplate.html
|
|
Integration with Velocity
|
The include() function works marvellously with static resources (HTML, XML, WML, TXT etc.) that
require no processing.
But most of the time, develloper need to output dynamic resources with a scripting language.
For those situations, jPortlet uses Velocity Template Language.
Each Velocity file (.vm ) will access the following variables:
A portlet that uses Velocity look like this:
XPortlet.java |
public class XPortlet
extends PortletAdapter
{
...
protected void doView( PortletRequest request,
PortletResponse response )
throws PortletException,
IOException
{
request.setAttribute( "name", "Fred" );
include( "view.vm" );
}
...
}
|
view.vm |
<p>
Hello ${name}
</p>
|
|
|
What about JSP ?
|
JSP not supported by jPortlet because of the inability to access JSP buffer using a consistent
API.
|
|
|