JSP and JSTL Tutorials - Tutorial Addendum - JSP Tag Aspect Administration

arcadegamesios wordgamesios lifestyleappsios
 31 December 18:00   

    



    



    

(Continued from antecedent part...)

    



    

Tag Aspect Amount Announcement Archetype - AttObjectTag.java

    



    

The tag class:

    

 

    

/**

    

* AttObjectTag.java

    

* Absorb (c) 2003 by Dr. Yang. All rights reserved.

    

*/

    

package ;

    

import java.util.*;

    

import java.io.*;

    

import javax.servlet.jsp.*;

    

import javax.servlet.jsp.tagext.*;

    

import org.apache.taglibs.standard.lang.support.*;

    

public chic AttObjectTag extends TagSupport {

    

clandestine Cord booleanAtt = null;

    

clandestine Boolean booleanObject = null;

    

clandestine Cord stringAtt = null;

    

clandestine Cord stringObject = null;

    

clandestine Cord mapAtt = null;

    

clandestine Map mapObject = null;

    

accessible abandoned setBooleanAtt(String att) {

    

booleanAtt = att;

    

try {

    

booleanObject =

    

(Boolean) ExpressionEvaluatorManager.evaluate(

    

"booleanAtt", booleanAtt, java.lang.Boolean.class,

    

this, pageContext);

    

} bolt (JspException e) {

    

System.err.println(e.toString());

    

}

    

}

    

accessible abandoned setStringAtt(String att) {

    

stringAtt = att;

    

try {

    

stringObject =

    

(String) ExpressionEvaluatorManager.evaluate(

    

"stringAtt", stringAtt, java.lang.String.class,

    

this, pageContext);

    

} bolt (JspException e) {

    

System.err.println(e.toString());

    

}

    

}

    

accessible abandoned setMapAtt(String att) {

    

mapAtt = att;

    

try {

    

mapObject =

    

(Map) ExpressionEvaluatorManager.evaluate(

    

"mapAtt", mapAtt, java.util.Map.class,

    

this, pageContext);

    

} bolt (JspException e) {

    

System.err.println(e.toString());

    

}

    

}

    

accessible int doStartTag() {

    

JspWriter out = pageContext.getOut();

    

try {

    

out.println("booleanAtt = "+booleanAtt+"<br/>");

    

out.println("booleanObject = "+booleanObject+"<br/>");

    

out.println("stringAtt = "+stringAtt+"<br/>");

    

out.println("stringObject = "+stringObject+"<br/>");

    

out.println("mapAtt = "+mapAtt+"<br/>");

    

if (mapObject!=null) {

    

out.println("mapObject.size = "+mapObject.size()+"<br/>");

    

} abroad {

    

out.println("mapObject = null<br/>");

    

}

    

} bolt (IOException e) {

    

System.err.println(e.toString());

    

}

    

acknowledgment SKIP_BODY;

    

}

    

}

    



    



    

The TLD file:

    

 

    

<?xml version="1.0"?>

    

<!DOCTYPE taglib Accessible

    

"-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"

    

"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_2.dtd">

    

<!-- HyTaglib.tld

    

Absorb (c) 2003 by Dr. Yang

    

-->

    

<taglib>

    

<tlib-version>1</tlib-version>

    

<jsp-version>1.2</jsp-version>

    

<short-name> s Tag Library</short-name>

    

<tag>

    

<name>attObject</name>

    

<tag-class>.AttObjectTag</tag-class>

    

<body-content>empty</body-content>

    

<attribute>

    

<name>booleanAtt</name>

    

<required>false</required>

    

</attribute>

    

<attribute>

    

<name>stringAtt</name>

    

<required>false</required>

    

</attribute>

    

<attribute>

    

<name>mapAtt</name>

    

<required>false</required>

    

</attribute>

    

</tag>

    



    

</taglib>

    



    



    

The JSP page:

    

 

    

<?xml version="1.0"?>

    

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"

    

xmlns:c="http://java.sun.com/jstl/core"

    

xmlns:hy="urn:jsptld:/WEB-INF/tlds/HyTaglib.tld" version="1.2">

    

<!-- AttObjectTagTest.jsp

    

Absorb (c) 2003 by Dr. Yang

    

-->

    

<jsp:directive.page contentType="text/html"/>

    

<html><body>

    

<p>Regular Strings:</p>

    

<hy:attObject booleanAtt="true" stringAtt="Hello world!"/>

    

<p>Literals:</p>

    

<hy:attObject booleanAtt="${false}" stringAtt="${ Yang }"/>

    

<p>Expressions:</p>

    

<hy:attObject booleanAtt="${1==1}"

    

stringAtt="${pageContext.request.method}"

    

mapAtt="${cookie}"/>

    

</body></html>

    

</jsp:root>

    



    



    

The output:

    

 

    

Regular Strings:

    

booleanAtt = true

    

booleanObject = true

    

stringAtt = Accost world!

    

stringObject = Accost world!

    

mapAtt = null

    

mapObject = null

    

Literals:

    

booleanAtt = ${false}

    

booleanObject = false

    

stringAtt = ${ Yang }

    

stringObject = Yang

    

mapAtt = null

    

mapObject = null

    

Expressions:

    

booleanAtt = ${1==1}

    

booleanObject = true

    

stringAtt = ${pageContext.request.method}

    

stringObject = GET

    

mapAtt = ${cookie}

    

mapObject.size = 0

    



    



    

Note that:

    



        

  • The JSTL announcement appraisal apparatus is a changeless method, evaluate(), in

        

    ExpressionEvaluationManager class, in org.apache.taglibs.standard.lang.support package.

        



  •     

  • The announcement rules are identical to those declared in JSTL, because we

        

    are using the aforementioned appraisal tool.

        



  •     

  • If you bang "refresh" button on the browser, the mapObject.size will be 1,

        

    because the affair id is stored in the cookie map.

        



  •     



    



    



    

 


Tags: system, world, class, attribute, support, catch, notes, public, string, tutorial, tutorials

 booleanatt, println, attribute, string, stringatt, class, mapatt, version, mapobject, private, public, required, import, stringobject, pagecontext, system, tostring, catch, booleanobject, evaluate, false<, xmlns, world, attobject, boolean, expression, expressionevaluatormanager, jspexception, copyright, attobjecttag, taglib, , attribute <, < attribute, null private, name <, < jsp, err println, < name, private string, system err, < tag, < body, < required, attobject booleanatt, html <, required <, false< required, required false<, http java, string att, att try, public void, tag class, tag attribute, expressionevaluatormanager evaluate, class this, java sun, jsp tag, mapobject size, catch jspexception, sun com, null private string, class this pagecontext, < required false<, required false< required, standard lang support, taglibs standard lang, apache taglibs standard, tutorials tutorial notes, tag attribute handling, import javax servlet, org apache taglibs, jstl tutorials tutorial,

Share JSP and JSTL Tutorials - Tutorial Addendum - JSP Tag Aspect Administration:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  jsp