Re: [ANN] Navigate and dynamic parameters

Gene McCullough <[email protected]>
Newsgroups gmane.comp.java.keel.devel
Message-ID <[email protected]>
I've updated Navigate.java in CVS, it now passes thru any parameter 
tokens found in the format ${tokenName} to the response as 
[keel_nav:tokenName[

I've modified the menubar.jsp (included below) jstl code to parse these 
values, and it really DOES replace them with outputs from the server. 
So, as it is now, the navigate model will replace the values with 
request parameters first, then request attributes, then outputs, then 
finally passes it on to the response to be parsed by the browser.

I think it prolly could be accomplished in a more elegant manner, but I 
couldn't come up with one.

hth, it works for me,
gene

<!-- menubar.jsp -->

<jsp:directive.page language="java" />

<%-- The output from this jsp can be included anywhere in the (X)HTML page.
      It uses the app-navigate parameter "menu" to make nested lists.

      No Javascript here, only CSS!

      Note: when the cursor goes out of any menu area, all the submenus 
vanish
            *immediatly*. To get some latence time, Javascript is needed.

      Note:
        - no model or empty => try to use an url if any, otherwise 
nothing appends
        - no url => nothing appends (but app-crud doesn't create a menu 
with neither model nor url)
        - empty url => href="", i.e. come back on the same page, but it 
seems this
                       behavior isn't always sure (as it depends the way 
browser completes the path)

      --%>

<!--included-->
<div id="navbar">
<c:if test="${! empty menu}">
   <ul class="level1">
   <c:forEach var="topelement" items="${menu.map.nested}">
     <c:set var="topelement_title" 
value="${topelement.map.attributes.map.title}" />
     <li class="submenu">
       <a name="${topelement_title}">${topelement_title}</a>
       <ul class="level2">
       <c:forEach var="secondelement" items="${topelement.map.nested}">
         <c:set var="secondelement_title" 
value="${secondelement.map.attributes.map.title}" />
         <c:set var="secondelement_type" value="href"/>
         <c:choose>
         <c:when test="${! empty secondelement.map.attributes.map.model}">
           <c:set var="secondelement_model" 
value="${secondelement.map.attributes.map.model}" />
           <c:url var="secondelement_path" 
value="/model.do?model=${secondelement_model}"/>
           <c:choose>
           <c:when test="${! empty 
secondelement.map.attributes.map.parameters}">
	  	<c:set var="nav_parameters" value="" />
			<c:forTokens var="token"
				items="${secondelement.map.attributes.map.parameters}"
				delims="[">
				<c:if test="${fn:startsWith(token, 'keel_nav:')}">
					<c:set var="thisOutput" value="${fn:replace(token, 'keel_nav:', '')}"/>
					<c:set var="token" value="${requestScope[thisOutput]}"/>
				</c:if>
				<c:set var="nav_secondparameters" 
value="${nav_secondparameters}${token}"/>
			</c:forTokens>
             <c:set var="secondelement_parameters" 
value="${nav_secondparameters}" />
             <c:set var="nav_secondparameters" value="" />
           </c:when>
           <c:otherwise>
             <c:set var="secondelement_parameters" value=""/>
           </c:otherwise>
           </c:choose>
         </c:when>
         <c:otherwise>
           <c:choose>
           <c:when test="${secondelement.map.attributes.map.url != 
null}"><%-- explicit equality test to force coercing rule  --%>
             <c:set var="secondelement_url" 
value="${secondelement.map.attributes.map.url}" />
             <c:url var="secondelement_path" value="${secondelement_url}"/>
           </c:when>
           <c:otherwise>
             <c:set var="secondelement_path" 
value="${secondelement_title}"/>
             <c:set var="secondelement_type" value="name"/>
           </c:otherwise>
           </c:choose>
           <c:set var="secondelement_parameters" value=""/>
         </c:otherwise>
         </c:choose>

         <li class="submenu">
           <a 
${secondelement_type}="${secondelement_path}${secondelement_parameters}">${secondelement_title}
           <c:choose>
           <c:when test="${empty secondelement.map['nested']}">
               </a>
           </c:when>
           <c:otherwise>
               <span>&gt;</span></a><%-- TODO: use an image ? and keep 
the character by default --%>
               <ul class="level3">
               <c:forEach var="thirdelement" 
items="${secondelement.map.nested}">
                 <c:set var="thirdelement_title" 
value="${thirdelement.map.attributes.map.title}" />
                 <c:set var="thirdelement_type" value="href"/>
                 <c:choose>
                 <c:when test="${! empty 
thirdelement.map.attributes.map.model}">
                     <c:set var="thirdelement_model" 
value="${thirdelement.map.attributes.map.model}" />
                     <c:url var="thirdelement_path" 
value="/model.do?model=${thirdelement_model}"/>
                     <c:choose>
                     <c:when test="${! empty 
thirdelement.map.attributes.map.parameters}">
					  	<c:set var="nav_parameters" value="" />
						<c:forTokens var="token"
							items="${thirdelement.map.attributes.map.parameters}"
							delims="[">
							<c:if test="${fn:startsWith(token, 'keel_nav:')}">
								<c:set var="thisOutput" value="${fn:replace(token, 'keel_nav:', 
'')}"/>
								<c:set var="token" value="${requestScope[thisOutput]}"/>
							</c:if>
							<c:set var="nav_thirdparameters" 
value="${nav_thirdparameters}${token}"/>
						</c:forTokens>
             			<c:set var="thirdelement_parameters" 
value="${nav_thirdparameters}" />
      			        <c:set var="nav_thirdparameters" value="" />
                     </c:when>
                     <c:otherwise>
                       <c:set var="thirdelement_parameters" value=""/>
                     </c:otherwise>
                     </c:choose>
                 </c:when>
                 <c:otherwise>
                     <c:choose>
                     <c:when test="${thirdelement.map.attributes.map.url 
!= null}"><%-- explicit equality test to force coercing rule  --%>
                       <c:set var="thirdelement_url" 
value="${thirdelement.map.attributes.map.url}" />
                       <c:url var="thirdelement_path" 
value="${thirdelement_url}"/>
                     </c:when>
                     <c:otherwise>
                       <c:set var="thirdelement_path" 
value="${thirdelement_title}"/>
                       <c:set var="thirdelement_type" value="name"/>
                     </c:otherwise>
                     </c:choose>
                     <c:set var="thirdelement_parameters" value=""/>
                 </c:otherwise>
                 </c:choose> <%-- third element : model empty ? --%>
                 <li><a 
${thirdelement_type}="${thirdelement_path}${thirdelement_parameters}">${thirdelement_title}</a></li>
               </c:forEach> <%-- third element --%>
               </ul>
           </c:otherwise>
           </c:choose> <%-- second element : model empty ? --%>
         </li>
       </c:forEach> <%-- all second-level elements --%>
       </ul>
     </li>
   </c:forEach> <%-- top level elements --%>
   </ul>
</c:if> <%-- menu --%>
</div>

http://keelframework.org/documentation.shtml
Keelgroup mailing list
[email protected]
http://lists.keelframework.com/listinfo.cgi/keelgroup-keelframework.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.