C: foreach label of jstl

Source: Internet
Author: User
In the TLD, <C: foreach>: <tag> <Name> foreach </Name> <tag-class> Org. apache. taglibs. standard. tag. el. core. foreachtag </Tag-class> <Tei-class> Org. apache. taglibs. standard. tei. foreachtei </Tei-class> <body-content> JSP </body-content> <description> the basic iteration tag, accepting divide different collection types and supporting subsetting and other functionality </description> <attribute> <Name> items </Name> <required> false </required> <rtexprvalue> false </ rtexprvalue> </attribute> <Name> begin </Name> <required> false </required> <rtexprvalue> false </rtexprvalue> </attribute> <attribute> <Name> end </Name> <required> false </required> <rtexprvalue> false </rtexprvalue> </attribute> <Name> step </Name> <required> false </required> <rtexprvalue> false </rtexprvalue> </attribute> <Name> var </Name> <required> false </required> <rtexprvalue> false </rtexprvalue> </attribute> <Name> varstatus </Name> <required> false </required> <rtexprvalue> false </rtexprvalue> </attribute> </Tag>
<C: foreach> A tag has the following attributes:

VaR: the name of the iteration parameter. The name of the variable that can be used in the iteration body to represent each iteration variable. The type is string.

Items: the set to be iterated. The supported types are described below.

Varstatus: the name of the iteration variable. It is used to indicate the iteration status and can access the information of the iteration itself.

Begin: If items is specified, iteration starts from items [begin]. If items is not specified, iteration starts from begin. Its type is an integer.

End: If items is specified, the iteration ends at items [end]. If items is not specified, the iteration ends at end. Its type is also an integer.

Step: the iteration step.

<C: foreach> the items attribute of the tag supports all standard set types provided by the Java platform. In addition, you can use this operation to iterate elements in an array (including an array of basic types. It supports the following Collection types and iteration elements:

Java. util. Collection: Elements obtained by calling iterator.
 
Java. util. MAP: the Instance obtained through java. util. Map. Entry.

Java. util. iterator: iterator element.

Java. util. enumeration: enumeration element.

Object instance array: array element.

Basic Type value array: Elements of the encapsulated array.

String to be separated by commas (,): The Sub-string after segmentation.

Javax. servlet. jsp. jstl. SQL. Result: The row obtained by the SQL query.

Whether it is an integer or an iteration of a set, the varstatus attribute of <C: foreach> plays the same role. Like the VaR attribute, varstatus is used to create a variable with a limited scope (the change volume only works in the current TAG body ). However, the variable named by the varstatus attribute does not store the current index value or the current element, but is assigned to an instance of the javax. servlet. jsp. jstl. Core. looptagstatus class. This class contains a series of features that describe the current state of iteration. The meanings of these attributes are as follows:

Current: the items in the current iteration (in the set.

Index: The index of the current iteration that starts from 0.

Count: the number of iterations of the current iteration starting from 1.

First: indicates whether the current iteration is the first iteration. This attribute is of the boolean type.

Last: indicates whether the current iteration is the last iteration. This attribute is of the boolean type.

Begin: the value of the begin attribute.

End: End Attribute Value

Step: the value of the Step attribute.
Using the varstatus attribute: There is a pure way to desplay chekbox with two collums
In JSP page. checkboxlists is a set of checkboxto, which contains the key, value, and checke attributes.

  1. <C: foreach items = "$ {checkboxlist}" begin = "0" step = "2" varstatus = "status">
  2. <Tr>
  3. <TD> <C: Out value = "$ {status. index} "/> <input type =" checkbox "value = '<C: Out value =" $ {checkboxlist [status. index]. key} "/>'
  4. <C: If test = "$ {checkboxlist [status. Index]. Checked EQ true}"> checked = "checked" </C: If>
  5. /> <C: Out value = "$ {checkboxlist [status. Index]. Value}"/>
  6. </TD>
  7.  
  8. <TD> <C: If test = "$ {! Empty checkboxlist [status. index + 1]} "> <! -- Determine whether there is another record, for odd -->
  9. <C: Out value = "$ {status. index + 1} "/> <input type =" checkbox "value = '<C: Out value =" $ {checkboxlist [status. index + 1]. key} "/>'
  10. <C: If test = "$ {checkboxlist [status. index + 1]. Checked EQ true}"> checked = "checked" </C: If>
  11. /> <C: Out value = "$ {checkboxlist [status. index + 1]. Value}"> </C: Out>
  12. </C: If>
  13. </TD>
  14. </Tr>
  15. </C: foreach>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.