Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
<%@taglib uri="http://web.mit.edu/ist/isda/tags/navigation" prefix="nav" %>

This section details the various object beans which can be exposed through The following section describes all the tags in the navigation tag library.

...

  Unless stated otherwise, these objects are in the edu.mit.isda.navigation package.  Also, all properties of these objects are read-only.  You cannot alter them in any way within a JSP.

This is an object representing the site tree.  There is really only one important property here: homeSection, which corresponds to the topmost url (usually "/") in the site.

Properties

Name

Type

Description

homeSection

Section

an object representing the Home Page (or Home Section) for the web site.   You can recurse the tree starting from this section using the <nav:treeWalk> and <nav:

...

subtreeWalk tags>.

lastUpdated

java.util.Date

the datestamp when this site tree object was created.   The site tree returned by <nav:setSiteTreeVar> should always be fairly new.   If you are using a cached or stored SiteTree object (not recommended) this could be older.  This property is provided primarily to help webapp developers develop and debug their application.

timeToCreate

long

the time in milliseconds that it took to create this site tree object.  It is a measure of how long it takes for the webapp to crawl the site.  If the servlet container is running many such threads (virtualization server, hint hint) this could be a long-ish time.  This property is provided primarily to help webapp developers develop and debug their application.

This is an object representing a page or a section within the site tree.   The basic object is a Page, which has a title and a URL.  A Section is a special type of Page, which contains subpages.  If a Page is not a Section, it does not contain subpages.  (Note that all Section objects are Pages, but not all Page objects are Sections.)   To ease JSP programming, you can just treat all Sections as Pages, and use the "isASection" and "subpages" properties to access section-specific behavior.

Properties

Name

Type

Description

title

String

the title for this Page or Section.

url

String

the URL for this Page or Section.

breadcrumb

java.util.List<Page>

the breadcrumb for this Page or Section.  This is a List of all this Page's ancestors in the site tree, starting from the Home section and ending at the current Page.  You can iterate through this collection using the <c:forEach> tag in the JSTL.

containingSection

Section

this Page's parent Section.  This is nullif the current Page is the home section (root) of the site tree.  The containingSection has the current Page as one of its subpages.

isASection

boolean

true if the current Page is also a Section (can have subpages).
false if the current Page is not a Section (cannot have subpages).

subpages

java.util.Collection<Page>

if this Page is also a Section: a Collection of all the Pages and Sections contained in this Section.   Every element in this Collection has the current Page as its containingSection.  You can iterate through this collection using the <c:forEach> tag in the JSTL.
if this Page is not also a Section: an empty Collection.

isExternal

boolean

true if the current Page corresponds to a local root-relative url in the current webapp.
false if the current Page corresponds to an external absolute url.

 

The following section describes the tags in the navigation tag library, as well as giving some example of how they are used in conjunction with the above bean properties

 This <nav:setSiteTreeVar> action sets a scoped variable to the object representing the site tree.  The site tree bean is useful for a JSP which generates a Site Index or Site Map page.  Once you have set a variable to the site tree bean, you can walk through it with the <nav:treeWalk> and <nav:subTreeWalk> tags.

It is not recommended to save the site tree to session or application scope for later use, as it will possibly be stale (if pages have been added or removed without restarting the webapp).  Instead, just use <nav:setSiteTreeVar> again when you need the most recent site tree.

Syntax

Wiki Markup
<nav:setSiteTreeVar \[var="_var_"\] \[scope="*page*\|request\|session\|application"\] />

Attributes

Attribute name

Java type

Default
value

Dynamic value
accepted

Description

var

String

"siteTree"

No

The name of the variable to contain the site tree object.

scope

String

"page"

No

The scope for the variable.  It must be one of "page", "request", "session", or "application".

Example

No Format

<nav:setSiteTreeVar var="theSiteTree" />
The Site Tree was last updated at <fmt:formatDate value="${theSiteTree.lastUpdated}" pattern="h:mm:ss a" />

The <nav:treeWalk> and <nav:subtreeWalk> actions allow you to recursively walk through the site tree (or any tree structure). The idea is that the body of the <nav:treeWalk> tag is performed for every branch of the tree. The body of the <nav:treeWalk> tag must contain the <nav:subtreeWalk> tag, which indicates where to include the sub-branches in the tree walk. It's much easier to look at an example than to explain what I mean.

Note that this is a simple tag, so you may not include jsp scripting elements (<% ... %>, <%= ... %>, etc.) inside the body of the <nav:treeWalk> tag. You must use only JSP tags inside the body. 

Also note that if you try to walk the same node twice, an exception will be thrown.  This prevents infinite regress in the case of faulty logic or a cyclical tree object. 

It is not recommended to save the site tree to session or application scope for later use, as it will possibly be stale (if pages have been added or removed without restarting the webapp).  Instead, just use <nav:setSiteTreeVar> again when you need the most recent site tree.

Syntax

Wiki Markup
<nav:setSiteTreeVar \[var="_var_"\] \[scope="*page*\|request\|session\|application"\] />

Attributes

Attribute name

Java type

Default
value

Dynamic value
accepted

Description

var

String

"siteTree"

No

The name of the variable to contain the site tree object.

scope

String

"page"

No

The scope for the variable.  It must be one of "page", "request", "session", or "application".

Example

No Format

<nav:setSiteTreeVar var="theSiteTree" />
The Site Tree was last updated at <fmt:formatDate value="${theSiteTree.lastUpdated}" pattern="h:mm:ss a" />

The <nav:treeWalk> and <nav:subtreeWalk> actions allow you to recursively walk through the site tree (or any tree structure). The idea is that the body of the <nav:treeWalk> tag is performed for every branch of the tree. The body of the <nav:treeWalk> tag must contain the <nav:subtreeWalk> tag, which indicates where to include the sub-branches in the tree walk. It's much easier to look at an example than to explain what I mean.

Note that this is a simple tag, so you may not include jsp scripting elements (<% ... %>, <%= ... %>, etc.) inside the body of the <nav:treeWalk> tag. You must use only JSP tags inside the body. 

Also note that if you try to walk the same node twice, an exception will be thrown.  This prevents infinite regress in the case of faulty logic or a cyclical tree object. 

Syntax

Wiki Markup
<nav:treeWalk \[root="_theRootObject_"\] \[var="_currentNodeObjectVar_"\] \[depth="_currentDepthVar_"\] >
&nbsp; ...
&nbsp; <nav:subtreeWalk subroot="_subNodeObject_" />
&nbsp; ...
</nav:treeWalk>

Attributes

Attribute name

Java type

Default
value

Dynamic value
accepted

Description

root

Object
(should be tree-like)

the home section of the current site tree

Yes

The root object of the tree to be walked.

var

String

"var"

No

The name of the nested variable holding the current node in the tree.

depth

String

(No default value, ignored)

No

An optional variable name to expose the depth of the current node in the tree.  If this is included, the variable will be set to an integer representing how many levels down the tree the current node is, with 0 representing the root node, 1 representing a child of the root node, and so on.

subroot

Object
(should be tree-like)

(Required attribute)

Yes

The object below the current node to become the new current node of the tree.

Example

The following example performs a fairly simple walk through the site tree, producing a set of nested bulleted lists representing all the sections/pages and subpages/subsections in the site. 

No Format

<nav:setSiteTreeVar var="theSiteTree" />
<h3><ul><li>
  <nav:treeWalk root="${theSiteTree.homeSection}" var="page">
     <a href="${page.url}"          ><c:out value="${page.title}" /></a>:<br/>
       <ul><c:forEach items="${page.subpages}" var="subpage">
         <li><nav:subtreeWalk subroot="${subpage}" /></li>
       </c:forEach></ul>
  </nav:treeWalk>
</li></ul></h3>

 This <nav:setBreadcrumbVar> action sets a scoped variable to an object representing the breadcrumb for a particular target url in the site.   In this case, the breadcrumb object is a list of the target's ancestor pages, starting from the home page of the site and ending at the target page.  This is useful for a JSP which generates a breadcrumb for the current page.   Once you have set a variable to a breadcrumb object, you can iterate through it within a <c:forEach> tag.

It is not recommended to save the breadcrumb to session or application scope for later use, as it will possibly be stale (if pages have been added or removed without restarting the webapp).  Instead, just use <nav:setBreadcrumbVar> again when you need the most recent breadcrumb.

Syntax

Wiki Markup
<nav:setBreadcrumbVartreeWalk \[urlroot="_"targetUrltheRootObject_"\] \[var="_varcurrentNodeObjectVar_"\] \[scopedepth="*page*\|request\|session\|application"\] />

Attributes

Attribute name

Java type

Default
value

Dynamic value
accepted

Description

url

String

the url of the currently requested page

No

The url of the page whose breadcrumb is desired.  For best results, this should be a root-relative url beginning with a slash (e.g., "/foo/bar/baz.html"). 

var

String

"breadcrumb"

No

The name of the variable to contain the breadcrumb object.

scope

String

"page"

No

The scope for the variable.  It must be one of "page", "request", "session", or "application".

Example

The following example gets and displays a breadcrumb for the currently requested page, since the "url" attribute is not set.  (Tip: This can be saved into its own JSP which is included in all JSPs on the web site to give a consistent breadcrumb look and feel and to avoid code duplication.)

No Format

<nav:setBreadcrumbVar var="breadcrumb" />
<c:forEach var="page" items="${breadcrumb}" varStatus="status">
<c:if test="${not status.first}">&gt;</c:if><a href="${page.url}"       ><c:out value="${page.title}" /></a>
</c:forEach>

"_currentDepthVar_"\] >
&nbsp; ...
&nbsp; <nav:subtreeWalk subroot="_subNodeObject_" />
&nbsp; ...
</nav:treeWalk>

Attributes

Attribute name

Java type

Default
value

Dynamic value
accepted

Description

root

Object
(should be tree-like)

the home section of the current site tree

Yes

The root object of the tree to be walked.

var

String

"var"

No

The name of the nested variable holding the current node in the tree.

depth

String

(No default value, ignored)

No

An optional variable name to expose the depth of the current node in the tree.  If this is included, the variable will be set to an integer representing how many levels down the tree the current node is, with 0 representing the root node, 1 representing a child of the root node, and so on.

subroot

Object
(should be tree-like)

(Required attribute)

Yes

The object below the current node to become the new current node of the tree.

Example

The following example performs a fairly simple walk through the site tree, producing a set of nested bulleted lists representing all the sections/pages and subpages/subsections in the site. 

No Format

<nav:setSiteTreeVar var="theSiteTree" />
<h3><ul><li>
  <nav:treeWalk root="${theSiteTree.homeSection}" var="page">
     <a href="${page.url}"              ><c:out value="${page.title}" /></a>:<br/>
       <ul><c:forEach items="${page.subpages}" var="subpage">
         <li><nav:subtreeWalk subroot="${subpage}" /></li>
       </c:forEach></ul>
  </nav:treeWalk>
</li></ul></h3>

 This <nav:setBreadcrumbVar>  This <nav:setPageVar> action sets a scoped variable to an object representing the navigation information for a particular target url in the site.   breadcrumb for a particular target url in the site.   In this case, the breadcrumb object is a list of the target's ancestor pages, starting from the home page of the site and ending at the target page.  This is useful for a JSP which needs to know, for example, the list of links generates a breadcrumb for the current page or section.   Once you have set a variable to a breadcrumb object, you can iterate through it within a <c:forEach> tag.

It is not recommended to save the page object breadcrumb to session or application scope for later use, as it will possibly be stale (if pages have been added or removed without restarting the webapp).  Instead, just use <nav:setPageVar> setBreadcrumbVar> again when you need the most recent page objectbreadcrumb.

Syntax

Wiki Markup
<nav:setPageVarsetBreadcrumbVar \[url=_"targetUrl_"\] \[var="_var_"\] \[scope="*page*\|request\|session\|application"\] />

...

Attribute name

Java type

Default
value

Dynamic value
accepted

Description

url

String

the url of the currently requested page or section

No

The url of the page whose breadcrumb is desired page.  For best results, this should be a root-relative url beginning with a slash (e.g., "/foo/bar/baz.html"). 

var

String

"pagebreadcrumb"

No

The name of the variable to contain the page breadcrumb object.

scope

String

"page"

No

The scope for the variable.  It must be one of "page", "request", "session", or "application".

Example

The following example gets and displays a bulleted list of all links underneath breadcrumb for the currently requested page, since the "url" attribute is not set.  (Tip: This can be saved into its own JSP which is included in all JSPs on the web site to give a consistent subnavigation breadcrumb look and feel and to avoid code duplication.)

No Format
<nav:setPageVar var="page"/:setBreadcrumbVar var="breadcrumb" />
<c:forEach var="page" items="${breadcrumb}" varStatus="status">
<c:forEach var="subpage" itemsif test="${pagenot status.subpagesfirst}" >
&bull; <agt;</c:if><a href="${subpagepage.url}"           ><c:out value="${subpagepage.title}" /></a><br/>a>
</c:forEach>

This section details the various object beans which can be exposed through the above tags.  Unless stated otherwise, these objects are in the edu.mit.isda.navigation package.  Also, all properties of these objects are read-only.  You cannot alter them in any way within a JSP.

This is an object representing the site tree.  There is really only one important property here: homeSection, which corresponds to the topmost url (usually "/") in the site.

Properties

Name

Type

Description

homeSection

Section

an object representing the Home Page (or Home Section) for the web site.

lastUpdated

java.util.Date

the datestamp when this site tree object was created.   The site tree returned by <nav:setSiteTreeVar> should always be fairly new.   If you are using a cached or stored SiteTree object (not recommended) this could be older.  This property is provided primarily to help webapp developers develop and debug their application.

timeToCreate

long

the time in milliseconds that it took to create this site tree object.  It is a measure of how long it takes for the webapp to crawl the site.  If the servlet container is running many such threads (virtualization server, hint hint) this could be a long-ish time.  This property is provided primarily to help webapp developers develop and debug their application.

...

:forEach>

 This <nav:setPageVar> action sets a scoped variable to an object representing the navigation information for a particular target url in the site.   This is useful for a JSP which needs to know, for example, the list of links for the current page or section.  

It is not recommended to save the page object to session or application scope for later use, as it will possibly be stale (if pages have been added or removed without restarting the webapp).  Instead, just use <nav:setPageVar> again when you need the most recent page object.

Syntax

Wiki Markup
<nav:setPageVar \[url=_"targetUrl_"\] \[var="_var_"\] \[scope="*page*\|request\|session\|application"\] />

Attributes

Attribute name

Java type

Default
value

Dynamic value
accepted

Description

url

String

the url of the currently requested page or section

No

The url of the desired page.  For best results, this should be a root-relative url beginning with a slash (e.g., "/foo/bar/baz.html"). 

var

String

"page"

No

The name of the variable to contain the page object.

scope

String

"page"

No

The scope for the variable.  It must be one of "page", "request", "session", or "application".

Example

The following example displays a bulleted list of all links underneath the currently requested page, since the "url" attribute is not set.  (Tip: This can be saved into its own JSP which is included in all JSPs on the web site to give a consistent subnavigation look and feel and to avoid code duplication.)

No Format

<nav:setPageVar var="page"/>
<c:forEach var="subpage" items="${page.subpages}" >
&bull; <a href="${subpage.url}"           ><c:out value="${subpage.title}" /></a><br/>
</c:forEach>