JSTL script for left pane of Linker
from
davistv
on Nov 04, 2008 05:18 PM
Hello,
I hacked together a little JSTL script a few months ago to generate
the javascript data structure used by the left pane of the Linker
plugin. This is not a true hierarchical implementation, I'm not doing
any recursion. But it works very well with a nav system that is
composed of 2 levels, and should serve as a simple example for more
complex implementations. Here's the database structure it assumes:
sections
- intSectionID
pages
- intPageID
- strName
- strUrl
section_pages
- intSectionID
- intPageID
- intStatusID
- intSortOrder
So there are many pages in a section, the section_pages table relates
pages to sections. Our system reserves a section with intSectionID ==
1 for the home page, thus the WHERE statement on the first query. I'll
paste the JSTL below, I hope someone finds it useful.
Cheers,
Troy
---
xinhaLinkScan.jsp
---
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/sql.tld" prefix="sql" %>
<%@ taglib uri="/WEB-INF/tld/fn.tld" prefix="fn" %>
[<%-- Start data structure --%>
<%-- Get list of sections first, minus home page --%>
<sql:query var="sections">
SELECT intSectionID from sections
WHERE intSectionID > 1
</sql:query>
<c:forEach var="thisSection" items="${sections.rows}"
varStatus="sectionsStatus">
<c:if test="${not sectionsStatus.first}">, </c:if>
<%-- Get section_pages entries for this section --%>
<sql:query var="pages">
SELECT pages.intPageID, pages.strName, pages.strUrl,
section_pages.intStatusID
FROM pages, section_pages
WHERE section_pages.intSectionID = ? AND pages.intPageID =
section_pages.intPageID
ORDER BY section_pages.intSortOrder
<sql:param value="${thisSection.intSectionID}" />
</sql:query>
<c:forEach var="Page" items="${pages.rows}" varStatus="pagestatus">
<c:set var="PageId" value="/content.jsp?PageId=${Page.intPageID}" />
<c:if test="${not empty Page.strUrl}">
<c:set var="PageId" value="${Page.strUrl}" />
</c:if>
<c:choose>
<c:when test="${pagestatus.first}">
{ url: '${PageId}'
<c:if test="${not pagestatus.last}">
, children: [ {
<c:set var="hasChildren" value="true" />
</c:if>
</c:when>
<c:otherwise>
url: '${PageId}'
</c:otherwise>
</c:choose>
<c:if test="${not pagestatus.last && not pagestatus.first}">
}, {
</c:if>
<c:if test="${pagestatus.last}">
}
<c:if test="${hasChildren == true && not sectionsStatus.last && not
pagestatus.first}"> ] }</c:if>
</c:if>
</c:forEach>
<c:if test="${sectionsStatus.last && hasChildren == true}">]</c:if>
<c:if test="${sectionsStatus.last}">}</c:if>
</c:forEach>
<%-- Finish array structure and print output for Xinha --%>
]