net.sf.tacos.services.SiteMap Service
The tacos demo application uses the SiteMap service to create all of the navigation and orgnaization of pages in the web application.
To use the SiteMap service to construct your page navigation scheme you need to add the SiteMap service to your hivemind configuration, as well as provide a sitemap.xml (or whatever name you want) configuration definition of your site.
Hivemind Configuration
<module id="yourmoduleid" version="1.0.0"> SiteMap configuration of navigation <service-point id="SiteMap" interface="net.sf.tacos.services.SiteMap"> <invoke-factory service-id="hivemind.BuilderFactory" model="singleton" > <construct class="net.sf.tacos.services.impl.SiteMapImpl" initialize-method="initialize"> <set-resource property="resource" path="sitemap.xml"/> </construct> </invoke-factory> </service-point> </module>
Sample sitemap.xml
<?xml version="1.0" encoding="UTF-8"?> <sitemap> <page name="Home" desc="Core Components"/> <page name="core/DialogExample" desc="Dialog" /> <page name="core/SimpleTreeExample" desc="Simple Tree"/> <page name="ajax/Index" desc="Ajax"/> <page name="ajax/AutocompleteExample" desc="Autocomplete"/> <page name="ajax/EffectsExample" desc="Effects/Refresh"/> <page name="ajax/ExceptionHandlerExample" desc="Exception Handle"/> <page name="ajax/InlineEditBoxExample" desc="InlineEditBox" /> <page name="ajax/ProgressBarExample" desc="ProgressBar"/> <page name="ajax/TreeExample" desc="Tree"/> <page name="forms/Index" desc="Forms"/> <page name="forms/AjaxFormsExample" desc="Ajax Forms"/> <page name="forms/AjaxSubmitExample" desc="Ajax Submit" /> <page name="forms/DirtyFormExample" desc="Dirty Form"/> <page name="forms/FormEffectsExample" desc="Validation/Date Picker"/> <page name="tests/Index" desc="Tests" /> <page name="tests/DisconnectedListenerTest" desc="Disconnected Listener" /> <category name="Core"> <page name="Home"/> <page name="core/Dialog" /> <page name="core/SimpleTreeExample"/> </category> <category name="Ajax"> <page name="ajax/Index"/> <page name="ajax/AutocompleteExample"/> <page name="ajax/EffectsExample"/> <page name="ajax/ExceptionHandlerExample"/> <page name="ajax/InlineEditBoxExample"/> <page name="ajax/ProgressBarExample"/> <page name="ajax/TreeExample"/> </category> <category name="Forms"> <page name="forms/Index"/> <page name="forms/AjaxFormsExample"/> <page name="forms/AjaxSubmitExample" /> <page name="forms/DirtyFormExample"/> <page name="forms/FormEffectsExample"/> </category> <category name="Tests"> <page name="tests/Index" /> <page name="tests/DisconnectedListenerTest" /> </category> </sitemap>
More will be explained on the page heirarchies defined above, but looking at the demo application should give you a good idea of how it works.
SiteMap Components
No official components have been created yet to encapsulate all of the SiteMap functionality (nor do there need to be any, even though they will be built for ease of use), but the demo application has a good sample of using the as of yet un-documented SiteMap component contained under net.sf.tacos.components.
SiteMap Component Html
The first part provides the category listing. It iterates through the categories and tags the current link with an id="current". It then lists the pages for the categories, and tags the current list element with id="here".
<span jwcid="@If" condition="ognl:siteMap.getCategoryFromPage(page.pageName)"> <!-- Begin Category navigation --> <div id="nav"> <ul id="navlist"> <span jwcid="@Foreach" source="ognl:siteMap.getCategories()" value="ognl:category"> <span jwcid="@If" condition="ognl:siteMap.inCategory(page.pageName, category)"> <li> <a jwcid="@PageLink" page="ognl:siteMap.getDefaultPage(category).name" id="current"> <span jwcid="@Insert" value="ognl:siteMap.getDefaultPageDesc(category)"/> </a> </li> </span> <span jwcid="@If" condition="ognl:!siteMap.inCategory(page.pageName, category)"> <li> <a jwcid="@PageLink" page="ognl:siteMap.getDefaultPage(category).name"> <span jwcid="@Insert" value="ognl:siteMap.getDefaultPageDesc(category)"/> </a> </li> </span> </span> </ul> </div> <!-- End Category navigation --> <!-- Begin Category Page navigation --> <span jwcid="@If" condition="ognl:siteMap.getCategoryFromPage(page.pageName)" > <div id="module_nav"> <ul> <span jwcid="@Foreach" source="ognl:siteMap.getCategoryPages(page.pageName)" value="ognl:name"> <span jwcid="@If" condition="ognl:siteMap.getCategoryFromPage(page.pageName).defaultPage != name"> <span jwcid="@If" condition="ognl:name == page.pageName || siteMap.contains(name, page.pageName)"> <li class="here"> <a jwcid="@PageLink" page="ognl:name"> <span jwcid="@Insert" value="ognl:siteMap.getPageInfo(name).getDesc()"/> </a> </li> </span> <span jwcid="@If" condition="ognl:name != page.pageName"> <li> <a jwcid="@PageLink" page="ognl:name"> <span jwcid="@Insert" value="ognl:siteMap.getPageInfo(name).getDesc()"/> </a> </li> </span> </span> </span> </ul> </div> </span> <!-- End Category page navigation --> </span>
SiteMap Component JWC
<component-specification class="org.apache.tapestry.BaseComponent" allow-informal-parameters="yes"> <property name="name"/> <property name="category"/> <inject type="object" property="siteMap" object="service:tacos.services.SiteMap"/> </component-specification>
Resulting Output
<!-- Begin Category navigation --> <div id="nav"> <ul id="navlist"> <li><a href="/tacos-demo4/app?page=Home&service=page" id="current">Core Components</a></li> <li><a href="/tacos-demo4/app?page=ajax/Index&service=page">Ajax</a></li> <li><a href="/tacos-demo4/app?page=forms/Index&service=page">Forms</a></li> </ul> </div> <!-- End Category navigation --> <!-- Begin Category Page navigation --> <div id="module_nav"> <ul> <li class="here"><a href="/tacos-demo4/app?page=core/SimpleTreeExample&service=page">Simple Tree</a></li> <li><a href="/tacos-demo4/app?page=core/Dialog&service=page">Dialog</a></li> </ul> </div> <!-- End Category page navigation -->