The body tag with the label

2010-10-31  来源:本站原创  分类:Java  人气:115 

Body tag with the label, is to allow nested tags within the label, usually used to perform some logic operations such as judgments and circulation.

The body tag with the tag needs to inherit BodyTagSupport, the class contains a bodyContent property, the property on behalf of the body tag.

BodyTagSupport also contains two methods.

doAfterBodyO: Every time after processing the tag body to call the method.

void doInitBodyO: Start calling the method is called when the body tag.

If necessary, you can override these two methods.

The following is an example of iterator tag, how to develop a body tag with the label, the label body contains two properties: bean and the item, bean properties on behalf of a page within the List; the item on behalf of each of the List element. Label the source code is as follows:

public classMyiteratorTagextends BodyTagSupport / / labels need to send on behalf of a collection of object names private String bean; / / set the object element private String item; / / set the current index private int i = 0; privateint size; prl flight rate Li st <String> itemList; Ilbea port property setter methods public void setBean (String s) bean = s; Ilbean property getter methods public StringgetBea port () return bean; Ilitem property setter methods pUblic void setltem (String s) itern = s; Ilitem property The getter method publicStringgetItem () {return item; / / start processing the label, call the method. public int doStartTag () throws JspTagException1 / List from the page to get the range object itemLiat = (List <String? pageContext.getAttribute (bean); / / Get the length of List size = itemList.size ();// will set the current index value on the page variable in the range of itern pageContext.setAttribute (item, itemList.get (i); / / return value EVAL_BODY_BUFFERED. that need to calculate the body of the tag return EVAL_BODY_BUFFERED; / / handle each time after the body tag to call the method public int doAfterBody () throws JspException / / Move List object's index position i + +; 1 / If the index has been more than a collection of length if (i> = size) 1 / the index back to zero i = 0; 1 / no calculators body, direct calls doEndTag method return SKIP_BODY; / / will set the scope of the current element value of the item into the page properties pageContext.setAttribute (item, itemList.get (i ?);// cycle calculators body return EVAL_BODY_AGAIN; 1 / end body tag to call the method public int doEndTag () throws JspTagExceptiontry {/ / Output tab body content bodyContent.writeOut (pageContext.getOut (?);} catch (IOException ex) {throw new JspTagException ("Error"); return EVAL_PAGE ;

Here is a nested within the tag with attributes tag, which features a very simple, just get the properties from the page range, then the output on the page of the property value. The code is as follows: public class WritorTag extends TagSupport (Ilitem property, find the label item from the page properties, and output of property values private String item; Ilitem the setter methods public void setltern (String s) {item = s; Ilitern the getter method public Stringgetitern () return itern; / / start processing the label calls the method public int doStartTag () throwsJspTagExceptiontry {/ / search item from the page properties within, pageContext.getOut (). write ((String) pageContext.getAttribute (item)); catch (IOException ex) throw new JspTagException ("error / /); / / return EVAL_PAGE. to calculate the page output. return EVAL_PAGE;

Label class in dealing with the various methods, different return value corresponds to a different meaning, often has the following return value.

SKIP_BODY: the body does not handle labels, direct call doEndTagO method.

SKIP_PAGE: ignore the labels behind the JSP page.

EVAL_PAGE: tag end of the deal, deal directly with the page content.

EVAL_BODY_BUFFERED: processing the tag body.

EVAL_BODY_INCLUDE: processing the tag body, but ignores setBodyContentO and doInitBodyO methods.

EVAL_BODY_AGAIN: the body of the label recycling.

Two labels in the above configuration tag library, the tag library configuration snippet is as follows:

<! - Configure method on behalf of the device label ...> <tag> <! - Configuration tag name -> <narne> iterator </ narne ><!-- configuration tag implementation class → > <tag-class> rnytag.MylteratorTag </ tag-class> <! ... configuration tag tag body content -> <body-content> JSP </ body-content ><!-- configuration bean property> <attribute> <narne> bean </ narne> < required> true </ required> <rtexprvalue> true </ rtexprvalue> </ attribute ><!-- configuration item attributes of a> <attribute> <narne> itern </ narne> <required> true </ required> <rtexprvalue> true </ rtexprvalue> </ attribute> </ tag ><!-- configuration output tag - → <tag> <! ... configuration tag name of a> <name> write </ name> <1 - the implementation class configuration label a> <tag-class> mytag.WritorTag </ tag-class ><!-- body content of the label configuration label: labels can be empty -> <body-content> empty </ body-content> <! - - Configuration attribute item -> <attribute> <name> item </ name> <required> true </ required> <rtexprvalue> true </ rtexprvalue> </ attribute> </ tag>

Nested in the JSP code using the two labels as follows:
<% / / Create a List object List <String> a = new ArrayList <String> (); a.add ("hello"); a.add ("world"); a. Add ("java"); / / the scope of the List into the page properties apageContext.setAttribute ("a", a );%><!-- elements on the table -> <table border="l" bgcolor="dddd99"> <! - Use iterator tag to iterate on a List object -> <mytag:iteratorbea Estuary ::::lla"item:::: "item"> <tr> <td> <! - the output value of the property the second item > <mytag:write item="item"l> <ltd> </ tr> </ mytag: iterator> </ table>

Implementation of the results page shown in Figure 2.30.
[Img] http://new.51cto.com/files/uploadimg/20080825/115640952.jpg
[/ Img] tag iterator Figure 2.30 Note: this example only the iterator to iterate List page range, usage has been limited. Readers can be expanded to an attribute that specifies the scope of the search iterations, and the iteration goal is not limited to List, but the Collection, and even arrays. Most of the frameworks such as Struts, WebWork contains its own iterator tag.

相关文章
  • The body tag with the label 2010-10-31

    Body tag with the label, is to allow nested tags within the label, usually used to perform some logic operations such as judgments and circulation. The body tag with the tag needs to inherit BodyTagSupport, the class contains a bodyContent property,

  • 2009-12-13 Chuan Chi podcast java web - the traditional label with a simple tag (Reprinted) 2010-04-10

    In addition to JavaMail JavaWeb today is part of the last day, there are three days is to be a small project. Before learning to string together all the knowledge, prepare for high-level segment. Hei hei! Finally to the advanced section! Today, the m

  • JSP2 custom label (simple, with property, with the tag body) 2010-10-31

    References in the JSP 1.1 specification added a custom tag library specification, custom tag library is a very good presentation layer component technology. By using a custom tag library, you can encapsulate in a simple label complex functions. ....

  • JSP custom tag TLD documentation Xiangjie 2010-03-25

    Write a tld paging label, but a number inside a specific meaning forgot, - -! So a handful of Baidu. To clarify the meaning of some of the labels commonly used, as explained ================================================== ============== The first

  • JSP2.0 introduced in the Simple Tag Configuration 2010-09-02

    JSP2.0 in order to simplify the complexity of the label increased the production of Simple Tag SimpleTagSupport class label class. SimpleTagSupport class is to achieve SimpleTag interface. It only needs to implement a doTag () method can be, without

  • Use include and merge label - switched network 2010-10-29

    <! - Google Translate Element -> <! - Menu -> <! - End of menu -> <script src="http://www.google.com/buzz/api/button.js" type="text/javascript"> </ script> Use tags to reuse <include /> <br />

  • ajax the dom of access to xml tags 2009-04-25

    The following shows how to use the dom to get to from the service returns an XML DOM object, and get the XML document you want to get tag, a tag of child label, the label's content or very simple <?xml version="1.0" encoding="UTF-8"

  • Their understanding of the J2EE three-tier architecture (design patterns and software differences between the links) 2009-06-21

    As Figure 3 layer 1.J2EE points: Server-side business logic (with Business Logic Tier and data layers of durable, Businness Tier and the EIS Tier), server-side presentation layer (Web Tier), and the client presentation layer (Client Tier) J2EE design

  • Android development tools used by adb 2009-08-13

    Transfer from: http://www.javaeye.com/topic/260042 adb (Android Debug Bridge) is provided by Android a common debugging tools, with this tool, we can manage the device or the status of mobile phone simulator. Can also be used for the following steps:

  • js document query 2009-10-11

    document text block object - JavaScript scripting language to describe -------------------------------------------------- ------------------- Note: The page name attributes and JavaScript elements cited include the case name must be consistent Otherw

  • android Debug Bridge (adb) [switch] [to facilitate future View] 2010-03-29

    Have to admit that google thing to do is very intimate to the developers ~ ~ ~ very convenient for debugging, you can put the same real machine when the emulator debug, thread view, object view. . . . You just need a real machine to connect your data

  • Tags / TabActivity-depth study of 2010-03-29

    What label should be the most impressed by this Now we will study a series of extensions to the Wrote 1. TabActivity custom made labels in the bottom of the screen 2. The various labels can be used in the *. xml layout is defined can also be defined

  • Struts 1.2 2010-03-29

    Struts Basic concepts: 1. What is MVC? What's the use? 2. Controller structure 3. What is Struts? What's the use? 4. Struts content and environment configuration What is MVC? What's the use? MVC is a design framework, the program flow clear and easy

  • struts2 knowledge summary (reproduced) 2010-03-29

    1. The overall logic controller as a filter, is responsible for filtering all requests. The filter API reference category org.apache.struts2.disapatcher. FilterDispatcher 2. MVC: page request (jsp) -> logic controllers (Filter) -> Business Controlle

  • [Change] CSS feature priority Specificity 2009-01-12

    If the same element there are two or more conflicting CSS rules, the browser there are some basic rules to decide which one is very special to win. It may not be as other less important, the majority of cases you do not need to worry about conflict,

  • Joint programming of Java and XML DOM Posts 2010-03-31

    Joint programming of Java and XML DOM Posts Initial DOM Document Object Model DOM is the acronym for the document object model. I have mentioned before, XML is a tree data organization, so DOM is an object of the apple tree depicts. Popular to say th

  • 20 Best WordPress SEO Plugin 2010-03-17

    wordpress seo their effect in the blog / CMS program in very good. Some developers and dedication coupled with excellent SEO plug-in, non-technical blog people can make their own WordPress search engine unfriendly. Note: The following recommended Wor

  • Mail:: SpamAssassin:: Conf - SpamAssassin Configuration Guide 2010-04-02

    Mail:: SpamAssassin:: Conf - SpamAssassin configuration guide English version of the same address - http://spamassassin.apache.org/full/3.2.x/doc/Mail_SpamAssassin_Conf.html Revision and the translator Notes 2004/11/13 first release for SpamAssassin

  • Domestic and foreign - the ultimate e-commerce type site resources Daquan (middle), e-commerce development must see 2010-03-26

    This is the ultimate e-commerce type site, the second part of the corpus of resources, this section is a massive collection of design resources, including relevant e-commerce website design templates, themes, icons, material and so on. The first thir

  • Email template mechanism with Magento's email 2010-03-24

    Magento's Mage:: getModel ('core / email_template') model can be used to send letters. Step I. In your module (in fact, can any Module) and etc / config.xml to add the code under the root tag <config> <default> <{ A qualified name. 1}> &