Thursday, November 15, 2012

Cheat sheet (quick tutorial) on JSTL

Insert tags

<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

 _______

Set a JSTL variable from Java

<c:set scope="session" value="<%=propertyMap.get("debugsql")%>" var="debugsql"></c:set>

_______

Print value of all httprequest parameters:

<c:forEach var="par" items="${paramValues}">
    <c:out value="${par.key}=${par.value[0]}"></c:out>
</c:forEach>

_______

Read in Java a JSTL property with session scope

Object mydomainObj = session.getAttribute("mydomain");
String mydomain = (mydomainObj == null) ? "" : mydomainObj.toString();



_______

Check is a JSTL variable is null:

<c:if test="${not empty param.nesoadomain}">


_______

Run a SQL query:

<sql:query var="rsCMDBDS" dataSource="jdbc/cmdb">
select A.JDBCDRIVER, B.URL, B.USERNAME, B.ENCRYPTED_PASSWORD from DATASOURCES A, DATASOURCES_ENV B where A.DSNAME = B.DSNAME and A.DSNAME = 'wlsbjmsrpDataSource' and B.DOMAINNAME = '${mydomain}'
</sql:query>
_______

test for equal

<c:if test="${par.key eq 'synchronizeLocalTable'} ">

test for equal

<c:if test="${par.key ne 'synchronizeLocalTable'} ">
_______

increment a counter in a loop

<c:set var="count" value="0" scope="page" />
<c:set var="count" value="${count + 1}" scope="page"/>

_______



No comments: