December 21, 2014
Hot Topics:

Open Source-Based Portal-Lite

  • December 8, 2005
  • By Scott Nelson
  • Send Email »
  • More Articles »

Page Layout

Back in page.jsp, your pageBody value tells you which page layout to use. You'll look at the simple home layout here. Other layouts are available in the example download.

<%-- home.jsp --%>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
   <tiles:useAttribute name="tiles"
                       classname="java.util.List" ignore="true" />
   <tiles:useAttribute name="titles"
                       classname="java.util.List" ignore="true" />
   <tiles:useAttribute name="container"
                       classname="java.lang.String" />
   <tiles:useAttribute name="titleBar"
                       classname="java.lang.String" ignore="true" />
<table cellpadding="0" cellspacing="0" border="0" width="100%">
   <tr><td colspan="2">File: home.jsp</td></tr>
   <tr>
      <td valign="top" width="50%">
   <tiles:insert attribute="container">
      <tiles:put name="titleBar" value="<%= titleBar %>" />
      <tiles:put name="tile" value="<%= (String)tiles.get(0) %>" />
         </tiles:insert>
   <tiles:insert attribute="container">
      <tiles:put name="titleBar" value="<%= titleBar %>" />
      <tiles:put name="tile" value="<%= (String)tiles.get(1) %>" />
         </tiles:insert>
      </td>
      <td valign="top" width="50%">
   <tiles:insert attribute="container">
      <tiles:put name="titleBar" value="<%= titleBar %>" />
      <tiles:put name="tile" value="<%= (String)tiles.get(2) %>" />
         </tiles:insert>
      </td>
   </tr>
</table>

This page template requires three tiles. With a little more effort, you can create more dynamic templates like (again, see the download). Note that you do as little formatting as possible here, to mirror most portal products. You simply set the location of the portlets (aka Tiles) and let the container component handle the rest.

Of course, the container component is just there to manage the portlet, so like all good managers it does nothing more than delegate the work, like this:

<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
   <tiles:useAttribute name="title"
                       classname="java.lang.String" ignore="true" />
   <tiles:useAttribute name="tile"
                       classname="java.lang.String" ignore="true" />
   <tiles:useAttribute name="titleBar"
                       classname="java.lang.String" />
<divclass="portal-container">
   <tiles:insert attribute="titleBar">
   File: container.jsp Class: portal-container
      <tiles:put name="title" value="<%= title %>" />
</tiles:insert>
   <tiles:insert page="<%= tile %>" flush="true"/>
</div>

titleBar doesn't do much more. It simply puts the title where you would expect it, and provides some UI for it:

<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
   <tiles:useAttribute name="title"
                       classname="java.lang.String" />
   <tiles:useAttribute name="link"
                       classname="java.lang.String" ignore="true" />
<divclass="portal-titlebar">
File: titlebar.jsp Class: portal-titlebar Title:<%= title %>
</div>

And, finally, the tile value points to your portlet content, which can be a JSP or HTML with your portlet content. Here's what a bare example looks like:

Demonstrating Tab Navigation

Once the framework is defined in tiles-defs.xml and you have built your framework JSPs, you can create everything that a portal consists of without writing another line of code. Just drop your demo portlet HTML into the application, update your config file, and you've updated the portal.

Obviously, it won't make a good demo with file name strings all over, so be sure to remove them once you have built an attractive UI, like this:

A Production Quality Portal

Giving non-tech users a way to play with your work while you're not there is a reality of development. By embedding Tomcat and Java into a Web application, anyone (even your boss) can start the application with two double-clicks.

Imbedding Tomcat and Java

To imbed Tomcat and Java, create a folder to hold your full demo as shown below:

Folder Structure

I call mine CD, because the idea is to burn it to a CD for copying to laptops. In CD, you will need Tomcat, a start batch file, a stop batch file, and a link to your application.

start.bat is simply a modification of the one Tomcat provides and looks like this:

@echo off
if "%OS%" == "Windows_NT" setlocal
rem -------------------------------------------------------------
rem Start script for the CATALINA Server
rem
rem $Id: startup.bat,v 1.4 2002/08/04 18:19:43 patrickl Exp $
rem -------------------------------------------------------------


rem Guess CATALINA_HOME if not defined
if not "%CATALINA_HOME%" == "" goto gotHome
set CATALINA_HOME=.
set CATALINA_HOME="%CATALINA_HOME%jakarta-tomcat-5.0.19"
deltree "%CATALINA_HOME%workCatalina"
if exist "%CATALINA_HOME%bincatalina.bat" goto okHome
set CATALINA_HOME=..
:gotHome
if exist "%CATALINA_HOME%bincatalina.bat" goto okHome
echo The CATALINA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome

set JAVA_HOME=%CATALINA_HOME%j2sdk1.4.1_03

set EXECUTABLE=%CATALINA_HOME%bincatalina.bat

rem Check that target executable exists
if exist "%EXECUTABLE%" goto okExec
echo Cannot find %EXECUTABLE%
echo This file is needed to run this program
goto end
:okExec

rem Get remaining unshifted command line arguments and save them
rem in the
set CMD_LINE_ARGS=
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setArgs
:doneSetArgs

call "%EXECUTABLE%" start %CMD_LINE_ARGS%

:end
Likewise with stop.bat:
@echo off
if "%OS%" == "Windows_NT" setlocal
rem -------------------------------------------------------------
rem Stop script for the CATALINA Server
rem
rem $Id: shutdown.bat,v 1.3 2002/08/04 18:19:43 patrickl Exp $
rem -------------------------------------------------------------

rem Guess CATALINA_HOME if not defined
if not "%CATALINA_HOME%" == "" goto gotHome
set CATALINA_HOME=.
set CATALINA_HOME="%CATALINA_HOME%jakarta-tomcat-5.0.19"

if exist "%CATALINA_HOME%bincatalina.bat" goto okHome
set CATALINA_HOME=..
:gotHome
if exist "%CATALINA_HOME%bincatalina.bat" goto okHome
echo The CATALINA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome

set JAVA_HOME=%CATALINA_HOME%j2sdk1.4.1_03
set EXECUTABLE=%CATALINA_HOME%bincatalina.bat

rem Check that target executable exists
if exist "%EXECUTABLE%" goto okExec
echo Cannot find %EXECUTABLE%
echo This file is needed to run this program
goto end
:okExec

rem Get remaining unshifted command line arguments and save them
rem in the
set CMD_LINE_ARGS=
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setArgs
:doneSetArgs

call "%EXECUTABLE%" stop %CMD_LINE_ARGS%

:end

Your application link points like this:

http://localhost/mydemo/

Place the JDK inside your Tomcat path (j2sdk1.4.1_03 in this example).





Page 3 of 4



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel