SAS® AppDev Studio™ 3.0 Developer's Site
Source Code - JSTL EL Example
Application Files
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>
<html>
<head><title>Items Available</title></head>
<body>
<h3>Items Available </h3>
<%-- Parse XML document and get root in application scope attribute itemlist --%>
<jsp:include page="parseItemList.htm" />
<%-- Iterate through item list showing name, price of each item in table --%>
<table border="2" cellpadding="5">
<tr bgcolor="#CCCCCC">
<th>Manufacturer</th><th>Model</th><th>Item</th><th>Description</th><th>Price</th><th>Details</th>
</tr>
<%-- Note that select attribute uses XPath notation , not JSTL EL notation --%>
<x:forEach var="curItem" select="$itemlist/items/item">
<%-- save value of id attribute as string in curID (not rendered) --%>
<c:set var="curId">
<x:out select="$curItem/@id"/>
</c:set>
<%-- Render each cell content in row of table --%>
<tr>
<td><x:out select="$curItem/mfg"></x:out></td>
<td><x:out select="$curItem/model"></x:out></td>
<td><x:out select="$curItem/name"></x:out></td>
<td><x:out select="$curItem/description"></x:out></td>
<td align="right">$<x:out select="$curItem/price"></x:out></td>
<td>
<%-- Add parameter to url to indicate which item is in this row--%>
<c:url var="url" value="/showDetail.jsp?" >
<c:param name="id" value="${curId}"/>
</c:url>
<a href="<c:out value='${url}'/>">Details</a>
</td>
</tr>
</x:forEach>
</table>
</body>
</html>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>
<c:if test="${applicationScope.itemlist == null}" >
<c:import url="/WEB-INF/items.xml" var="xml" />
<x:parse xml="${xml}" var="itemlist" scope="application" />
</c:if>
<c:if test="${applicationScope.itemlist == null}" >
<p>Unable to find or parse /WEB-INF/itemlist.xml<br>
</c:if>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>
<html>
<head><title>Item Details</title>
</head>
<body>
<%-- include will re-parse xml if needed (e.g., came here by bookmark) --%>
<jsp:include page="parseItemList.htm" />
<%-- Select only the item with the id attribute matching query string id --%>
<x:set var="itemSel" select="$itemlist/items/item[@id=$param:id]"/>
<h3>
<x:out select="$itemSel/mfg"/>
<x:out select="$itemSel/model"/>
<x:out select="$itemSel/name"/>
</h3>
<p><x:out select="$itemSel/description"/>
<%-- Output bulleted list of each bullet element under selected item --%>
<ul>
<x:forEach var="bullet" select="$itemSel/bullet">
<li><x:out select="$bullet" /></li>
</x:forEach>
</ul>
<p>Shipping weight: <x:out select="$itemSel/ship/weight"/>
<x:out select="$itemSel/ship/weight/@unit"/>
<c:set var="shipLoc">
<x:out select="$itemSel/ship/loc"/>
</c:set>
<p>Usually ships within
<c:choose>
<c:when test="${shipLoc == 'warehouse'}" >
24 hours
</c:when>
<c:when test="${shipLoc == 'depot'}" >
1-2 days
</c:when>
<c:otherwise>
1-2 weeks
</c:otherwise>
</c:choose>
<c:set var="qty">
<x:out select="$itemSel/ship/stock"/>
</c:set>
<c:if test="${qty < 1}">
<p><b>Sorry, this item is temporarily out of stock.</b>
</c:if>
</body>
</html>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<items>
<item id="SH-001">
<mfg>SkyHiTech</mfg>
<model>SL-100S</model>
<name>SateLighter</name>
<description>Cigarette lighter with integrated GPS</description>
<bullet>Automatically locates nearest cigarette vending machine</bullet>
<bullet>Serves as a conventional cigarette lighter too</bullet>
<bullet>Requires 9V battery (not included)</bullet>
<price>229.95</price>
<ship qty="each">
<weight unit="oz">14</weight>
<loc>depot</loc>
<stock>13</stock>
</ship>
</item>
<item id="NR-021">
<mfg>NeverReady</mfg>
<model>NR-900X</model>
<name>-9 Volt battery</name>
<description>9V Battery w/ reversed polarity markings</description>
<bullet>Suitable for all devices needing minus 9 volts</bullet>
<price>3.95</price>
<ship qty="each">
<weight unit="oz">4</weight>
<loc>warehouse</loc>
<stock>23</stock>
</ship>
</item>
<item id="GS-001">
<mfg>NetScrape</mfg>
<model>VCO-01</model>
<name>Virtual Can Opener</name>
<description>Internet-ready can opener</description>
<bullet>Opens cans downloaded from the World Wide Web</bullet>
<bullet>Not for use with jars</bullet>
<price>5.95</price>
<ship qty="each">
<weight unit="oz">11</weight>
<loc>drop</loc>
<stock>-3</stock>
</ship>
</item>
</items>