Implementation of the struts2 label for Loop

Source: Internet
Author: User

 

Java code

<S: bean name =
"Org. Apache. struts2.util. Counter"
Id =
"Counter"
>


<S: Param name = "first"
Value =
"1"
/>


<S: Param name = "last"
Value =
"10"
/>


<S: iterator>

Counter: <s: property value = "Current-1"
/>


</S: iterator>

</S: bean>

The first attribute specifies the start value of the loop, and the last attribute specifies the end value of the loop. For other related attributes, you can view the source code of the org. Apache. struts2.util. Counter class. Enter the current value of the loop in the following iterator: Current-1

Counter class source code

/*
 

* $ ID: counter. Java 471756 15: 01: 43z husted $
 

*
 

* Licensed to the Apache Software Foundation (ASF) under one
 

* Or more contributor license agreements. See the notice file
 

* Distributed with this work for additional information
 

* Regarding copyright ownership. The ASF licenses this file
 

* To you under the Apache license, version 2.0 (
 

* "License"); you may not use this file except T in compliance
 

* With the license. You may obtain a copy of the license
 

*
 

* Http://www.apache.org/licenses/LICENSE-2.0
 

*
 

* Unless required by applicable law or agreed to in writing,
 

* Software distributed under the license is distributed on
 

* "As is" basis, without warranties or conditions of any
 

* Kind, either express or implied. See the license for
 

* Specific language governing permissions and limitations
 

* Under the license.
 

*/



Package
Org. Apache. struts2.util;




Import
Java. Io. serializable;






/**
 

* A bean that can be used to keep track of a counter.
 

* <P/>
 

* Since it is an iterator it can be used by the iterator tag
 

*
 

*/



Public
 
Class
Counter
Implements
Java. util. iterator, serializable {




Private
 
Static
 
Final
 
Long
Serialversionuid = 2796965881168060179l;




Boolean
Wrap =
False
;




// Attributes ------------------



Long
First =
1
;


Long
Current = first;


Long
Interval =
1
;


Long
Last =-
1
;






Public
 
Void
Setadd (
Long
Addition ){


Current + = addition;

}



Public
 
Void
Setcurrent (
Long
Current ){


This
. Current = current;


}



Public
 
Long
Getcurrent (){


Return
Current;


}



Public
 
Void
Setfirst (
Long
First ){


This
. First = first;


Current = first;

}



Public
 
Long
Getfirst (){


Return
First;


}



Public
 
Void
Setinterval (
Long
Interval ){


This
. Interval = interval;


}



Public
 
Long
Getinterval (){


Return
Interval;


}



Public
 
Void
Setlast (
Long
Last ){


This
. Last = last;


}



Public
 
Long
Getlast (){


Return
Last;


}



// Public -------------------



Public
 
Long
Getnext (){


Long
Next = current;


Current + = interval;



If
(WRAP & (current> last )){


Current-= (1
+ Last)-First );


}



Return
Next;


}



Public
 
Long
Getprevious (){


Current-= interval;



If
(WRAP & (current <first )){


Current + = (last-first + 1
);


}



Return
Current;


}



Public
 
Void
Setwrap (
Boolean
WRAP ){


This
. Wrap = wrap;


}



Public
 
Boolean
Iswrap (){


Return
Wrap;


}



Public
 
Boolean
Hasnext (){


Return
(Last =-
1
) | WRAP )?
True
: (Current <= last );


}



Public
Object next (){


Return
 
New
Long (getnext ());


}



Public
 
Void
Remove (){


// Do nothing



}

}

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.