Release 2.x‎ > ‎Development‎ > ‎

JSP Tag Library

Overview

A web-site developers usually focus on the user experience, site navigation and the applications "look and feel". One way to access Java APIs are to insert actual Java code into a Java Server Page (JSP). This is not considered to be a "best practice", it merges complex business/technical logic into the Presentation Tier (HTML/JSP). This makes the application hard to maintain and some Web developers may not be comfortable having Java code embedded within a web page.

Project OpenPTK provides a standards-based Java Server Pages (JSP) Tag Library for performing provisioning tasks. Instead of placing complex Java code in a web-page, simple XML-style tags are used. Web developers that have used other JSP Taglibs, like the Java Standard Tag Library (JSTL), will be comfortable using Project OpenPTK's taglib.

Configuration

Tag Description Syntax
getConnection Establish a connection to the OpenPTK Server <ptk:getConnection var="..." properties="..." scope="session"/>

Provisioning

Tag Description Syntax
doCreate Create a new subject <ptk:doCreate connection="..." input="..." output="..."/>
doRead Read a single subject <ptk:doRead connection="..." input="..." output=".."/>
doUpdate Update a subject <ptk:doUpdate connection="..." input="..." output="..."/>
doDelete Delete a subject <ptk:doDelete connection="..." input="..." output="..."/>
doSearch Search for one or more subjects <ptk:doSearch connection="..." input="..." output="..."/>

Password Management

Tag Description Syntax
doPasswordChange User specifies a new password <ptk:doPasswordChange connection="..." input="..." output="..."/>
doPasswordReset System resets passwords <ptk:doPasswordReset connection="..." input="..." output="..."/>

Input - Output - Attribute

Tag Description Syntax
addValue Add a value to a predefined Attribute <ptk:addValue input="..." attribute="..." value="..."/>
getAttribute Get an Attribute from the Output <ptk:getAttribute var="..." name="..." output="..."/>
getAttributesList Get the List of Attributes from the Output <ptk:getAttributesList var="..." result=".."/>
getName Get the name of the Attribute
var is optional. If no var data will be "inline"
<ptk:getName var="..." attribute="..."/>
getProperty Get the specified Property from either a Result or Output <ptk:getProperty name="..." var="..." [ output="..." | result="..." ] />
getResult Gets a single (first) Result from the Output <ptk:getResult var="..." output="..." />
getResultsList Gets a List of Results from the Output <ptk:getResultsList var="..." output="..." sizevar="..." />
getType Gets the type (as a String) of the Attribute
var is optional. If no var data will be "inline"
<ptk:getType var="..." attribute="..."/>
getUniqueId Get the UniqueId from the Result.
var is optional. If no var data will be "inline"
<ptk:getUniqueId [ var="..." ] result="..." />
getValue Get the specified (named) value from the Output.
var is optional. If no var data will be "inline"
<ptk:getValue [ var="..." ] [ attribute="..." | output="..." | result="..." ] name='...'/>
getValuesList Gets the List of Values from the specified Attribute <ptk:getValuesList attribute="..." var="..." sizevar="..."/>
setAttribute Creates an Attribute with the specified key and value and adds (sets) it to the Input <ptk:setAttribute input="..." key="..." value="..."/>
setInput Creates an Input with the specified name. <ptk:setInput var="..."/>
setProperty Set property on an Input <ptk:setProperty input="..." key="..." value="..."/>
setQuery Create a Query and add (set) it to an Input <ptk:setQuery input="..." name="..." value="..." type="..." var="..."/>
setUniqueId Sets the unique identifier for an Input <ptk:setUniqueId input="..." value="..."/>

Utility

Tag Description Syntax
getInformation Get the specified information from the Element <ptk:getInformation type="..." element="..."/>

Handling an Error condition:
Most of the tags will set the variable ptkError to String that has a length greater than 1.

Adding provisioning operations to a JSP web application is easy once Project OpenPTK is configured in your environment. Please reference the Project OpenPTK, Installation/Configuration Guide for details. The JSP example below illustrates how Project OpenPTK tags can be used to create a user:

 
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@taglib prefix="ptk" uri="http://www.openptk.org/taglib" %> 

<ptk:getConnection var="myconn" properties="openptk_client" scope="session"/> 
<ptk:setInput var="myinput"/> 
<ptk:setAttribute input="myinput" key="firstname" value="${param.fname}"/>
<ptk:setAttribute input="myinput" key="lastname" value="${param.lname}"/> 
<ptk:setAttribute input="myinput" key="email" value="${param.email}"/> 
<ptk:doCreate connection="myconn" input="myinput" output="myoutput"/> 
  • <%@taglib ...> maps Project OpenPTK's taglib to the prefix name of "ptk".
  • <ptk:getConnection ...> establish connectivity to back-end systems through the use of a property file.
  • <ptk:setInput ...> defines a "input" object. The input object is used to hold information that will be used by one of the provisioning tags.
  • <ptk:setAttribute ...> used to define attributes (key/value) that are added to the Input.
  • <ptk:doCreate ...> This tag performs the provisioning operation. This tag performs the create operation of the subject. The results of the tag's operation is returned in an output object.

All of the tags are implemented in the org.openptk.taglib Java package. The diagram below lists all the tags in the library. Each tag sub-classes a base class called ProvisionTag. The ProvisionTag abstract class defines a common set of variables and methods that are used by all of the tags. The ProvisionTag supports the JSP taglib architecture by extending the SimpleTagSupport class. Developers that want to create new provisioning tags should extend the ProvisionTag class.