Sunday 28 June 2015

OCEJWCD.- 8.Developing JSP pages using custom tags (part 2)

OCEJWCD (SCWCD) - 1Z0-899 - Web Component Developer Certification
8.4.Write JSP code using several standard tags.

In the previous sections we have reviewed the uses of standard tags. There is the option of defining custom tags, when JSTL and standard actions are not enough.

-Using tag files ( implement tag functionality in a JSP)
-Using tag handlers (implement tag functionality in java class)
  -Simple
  -Classic (previous to JSP2.0)

Example of tagFile:

Example of simple tag handler:

- Class that extends SimpleTagSupport and override doTag() method:

- Create TLD for the tag:



- Use the tags in a JSP:

see the tag file in directive:  <%@ taglib prefix="myTag" tagdir="/WEB-INF/tags" %>
and tag handler in directive: <%@ taglib prefix="simple" uri="simpleTag" %>


Results:
In the example the tag file includes a button and the tag handler adds line with text and a checkbox.

8.5.List capabilities of JSTL tags.

  • JSTL encapsulates, as simple tags, core functionality common to many JSP applications. A single tag and can be used on multiple JSP containers.
  • JSTL provides support for core iteration and control-flow features, text inclusion, internationalizaton-capable formatting tags, and XML-manipulation tags.
  • JSTL extensibility mechanisms: a framework for integrating custom tags with JSTL tags.

OCEJWCD (SCWCD) - 1Z0-899 - Web Component Developer Certification

Monday 22 June 2015

OCEJWCD.- 8.Developing JSP pages using custom tags (part1)

OCEJWCD (SCWCD) - 1Z0-899 - Web Component Developer Certification
8.1.Relate the JSTL to common job roles in web application development and understand the use of tags in JSP developments.

The Java Standard Tag Library is a collection of standard custom tags
JSTL have a set of libraries:
- Core library
- Formatting library
- XML library
- SQL library

8.2.Recognize correct syntax for tags.

  • To escape XML or set to default and attribute
<c:out value="${message} escapeXml="true"/>
<c:out value="${user} default ="usuario1" />
  • Looping
<c:forEach var="item" items="${itemList}">
  ${item}
</c:out>
  • Conditions
<c:if test=${number eq 5}>
  Condition 1 displayed
</c:if>
  • Nested conditions
<c:choose>
  <c:when test....
  </c:when>
  <c:otherwise>
  </c:otherwise>
</c:choose>
  • set variable in a scope or a bean/map attribute:
<c:set var="name" scope="session" value="user1"/> 
*by default page scope
<c:set target="${beanPerson}" property="name" value="user1"/>
*if the bean is null throws an exception


  • include content dynamically that can be external to the container
<c:import url="....>
  • url rewriting and encoding
<c:url value="input.jsp" var="inputURL">
  <c:param name="name" value="${name}"/>
</c:url>
8.3.Configure a JSP to use tags from the JSTL.

At application level the files: jstl.jar and standard.jar should be in WEB-INF/lib directory.

In the JSP the following declaration should exist to use JSTL: taglib directive

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

See an example in post ocejwcd-6-more-view-facilities in section  6.5

OCEJWCD (SCWCD) - 1Z0-899 - Web Component Developer Certification