July 27, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Open Source-Based Portal-Lite

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

Creating Portal Page Definitions

Finally, you create portal page definitions that implement the framework definitions. Again, this is nothing fancy because this is strictly to show how the approach works. Each page definition extends your mainLayout, adding elements specific to the page such as the currentTab value (which will be used in the navigation JSP to provide the You Are Here mode), the pageBody value that points to a JSP with a layout for our portlets, and list of portlet tiles (the actual content) and titles (so your titlebar has something to work with).

To make this all work, you need to have some corresponding entries in the <action-mappings> node of struts-config.xml3:

<action
        path="/home"
        type="org.apache.struts.actions.ForwardAction"
        parameter="homePage"
        />
        <action
            path="/directory"
            type="org.apache.struts.actions.ForwardAction"
            parameter="directory"
        />
        <action
            path="/resources"
            type="org.apache.struts.actions.ForwardAction"
            parameter="resources"
        />

Just to get things started, you'll create some empty JSPs for each listed in your tiles-definitions, and then fire up Tomcat and look at what you have so far:

Raw Portal View

Next, you'll add the minor coding necessary to make your Tiles site act like a portal application (for convenience and to encourage reuse, the associated JSPs live in a framework path).

<%-- body.jsp --%>
<%@ page import="org.apache.log4j.Logger" errorPage="error.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%    Logger logger =
      Logger.getLogger(this.getClass().getPackage().getName());%>
<html>
    <head>
        <title><tiles:getAsString name="title"/></title>
        <link rel="STYLESHEET" type="text/css"
              href="framework/demo.css">
    </head>
<body class="portal-body">
<%-- SEE WEB-INFtiles-defs.xml --%>
    <tiles:useAttribute name="currentTab"
                        classname="java.lang.String" />
    <tiles:useAttribute name="showMenu"
                        classname="java.lang.String" />
    <tiles:useAttribute name="menu"
                        classname="java.lang.String" />
    <tiles:useAttribute name="pageBody"
                        classname="java.lang.String" />
    <tiles:useAttribute name="titleBar"
                        classname="java.lang.String" />
    <tiles:useAttribute name="container"
                        classname="java.lang.String"
                        ignore="true" />
    <tiles:useAttribute name="tiles"
                        classname="java.util.List"
                        ignore="true" />
    <tiles:useAttribute name="titles"
                        classname="java.util.List"
                        ignore="true" />
    <tiles:useAttribute name="navLabels"
                        classname="java.util.List"
                        ignore="true" />
    <tiles:useAttribute name="navLinks"
                        classname="java.util.List"
                        ignore="true" />
    <div id="pageBody" class="portal-body-content">
      Page: body.jsp class: portal-body
        <tiles:insert attribute="header"/>
        <tiles:insert attribute="page">
            <tiles:put name="currentTab"
                       value="<%= currentTab %>" />
            <tiles:put name="pageBody"
                       value="<%= pageBody %>" />
            <tiles:put name="titles"
                       value="<%= titles %>" />
            <tiles:put name="showMenu"
                       value="<%= showMenu %>" />
            <tiles:put name="menu"
                       value="<%= menu %>" />
            <tiles:put name="navLabels"
                       value="<%= navLabels %>" />
            <tiles:put name="navLinks"
                       value="<%= navLinks %>" />
            <tiles:put name="tiles"
                       value="<%= tiles %>" />
            <tiles:put name="titleBar"
                       value="<%= titleBar %>" />
            <tiles:put name="container"
                       value="<%= container %>" />
        </tiles:insert>
    </div>
    <tiles:insert attribute="footer"/>
</body>
</html>

The useAttribute tags let you create a request variable that can be passed from component to component, such as currentTab, which is used by the navigation JSP for sense of place.

In the case of variables that may or may not exist in a given context, you have the ignore parameter (default is false). In body.jsp, you are using three components directly with the insert tag:

<tiles:insert attribute="header"/>
<tiles:insert attribute="page">...
<tiles:insert attribute="footer"/>

The page component will need values from your body, so you insert them like this:

<tiles:put name="currentTab"  value="<%= currentTab %>" />
<tiles:put name="pageBody"    value="<%= pageBody %>" />
<tiles:put name="titles"      value="<%= titles %>" />
<tiles:put name="showMenu"    value="<%= showMenu %>" />
<tiles:put name="menu"        value="<%= menu %>" />
<tiles:put name="navLabels"   value="<%= navLabels %>" />
<tiles:put name="navLinks"    value="<%= navLinks %>" />
<tiles:put name="tiles"       value="<%= tiles %>" />
<tiles:put name="titleBar"    value="<%= titleBar %>" />
<tiles:put name="container"   value="<%= container %>" />

Following this trail, you next go to your page.jsp:

<%-- page.jsp --%>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
    <tiles:useAttribute name="currentTab"
                        classname="java.lang.String" />
    <tiles:useAttribute name="pageBody"
                        classname="java.lang.String" />
    <tiles:useAttribute name="showMenu"
                        classname="java.lang.String" />
    <tiles:useAttribute name="navLabels"
                        classname="java.util.List"  ignore="true" />
    <tiles:useAttribute name="navLinks"
                        classname="java.util.List"  ignore="true" />
    <tiles:useAttribute name="tiles"
                        classname="java.util.List"  ignore="true" />
    <tiles:useAttribute name="titleBar"
                        classname="java.lang.String" ignore="true" />
    <tiles:useAttribute name="container"
                        classname="java.lang.String" ignore="true" />
<% if(showMenu.equalsIgnoreCase("true")){%>
    <divclass="horizontal-menu-single-container"  style="width:100%">
        <tiles:insert attribute="menu">
    <tiles:put name="currentTab" value="<%= currentTab %>" />
    <tiles:put name="navLabels"  value="<%= navLabels %>" />
    <tiles:put name="navLinks"   value="<%= navLinks %>" />
        </tiles:insert>
    </div>
<%}%>
<divclass="portal-primary-page">
    File: page.jsp class: portal-primary-page
       <tiles:insert attribute="pageBody">
            <%-- SEE tiles-defs.xml --%>
            <tiles:put name="tiles" value="<%= tiles %>" />
            <tiles:put name="titleBar" value="<%= titleBar %>" />
            <tiles:put name="container" value="<%= container %>" />
            <tiles:put name="navLabels" value="<%= navLabels %>" />
            <tiles:put name="navLinks" value="<%= navLinks %>" />
            <tiles:put name="currentTab" value="<%= currentTab %>" />
    </tiles:insert>
</div>

In page.jsp, the useAttribute tags can only access what has been passed in from body.jsp. page.jsp has the menu component and the pageBody component, which it passes on the values needed by each.

horizontalmenu.jsp is the first component that takes advantage of your list items.

<!-- horizontalmenu.jsp -->
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
   <tiles:useAttribute name="navLabels"  classname="java.util.List" />
   <tiles:useAttribute name="navLinks"   classname="java.util.List" />
   <tiles:useAttribute name="currentTab" classname="java.lang.String" />
<%-- HORIZONTAL MENU --%>
<divclass="portal-primary-menu-container">
File: horizontalmenu.jsp class: portal-primary-menu-container
   <table border="1" cellpadding="0" cellspacing="0" id="menu">
      <tr>
<% for(int i=0; i < navLabels.size(); i++){%>
         <td nowrap <%if(navLabels.get(i).equals(currentTab)){%>
             style="font-weight : bold; background-color : #ECECEC"
             <%}else{%>
             style="cursor:pointer;"
             onclick="location.href='<%= navLinks.get(i) %>';"
             <%}%>
             >
         <%= navLabels.get(i) %>
         </td>
<%    }%>
   </table>
</div>

Here, you loop through the navLabels and navLinks Lists to create your menu, and check your currentTab value to create a sense of place style.





Page 2 of 4



Comment and Contribute

 


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

 

 


Sitemap | Contact Us

Rocket Fuel