There are still a lot of materials on the Internet about the use of struts2 labels, but there is very little information about this number label. I don't know if it's too simple for anyone to write. I think this is still very useful. Write a few words.
Label definition file: struts-tags.tld under the struts2-core-x.x.x.jar package, excerpted the following definition:
Render a formatted number.
number
org.apache.struts2.views.jsp.NumberTag
empty
The currency to use for a currency format
currency
false
false
Whether grouping is used
groupingUsed
false
false
Deprecated. Use 'var' instead
id
false
false
Maximum fraction digits
maximumFractionDigits
false
false
Maximum integer digits
maximumIntegerDigits
false
false
Minimum fraction digits
minimumFractionDigits
false
false
Maximum integer digits
minimumIntegerDigits
false
false
The number value to format
name
true
false
Parse integer only
parseIntegerOnly
false
false
The rounding mode to use - not implemented yet as this required Java 1.6
roundingMode
false
false
Type of number formatter (currency, integer, number or percent, default is number)
type
false
false
Name used to reference the value pushed into the Value Stack
var
false
false
false
If you are interested, find the source code of the org. apache. struts2.views. jsp. NumberTag class below.
Write an example to make it clear:
Action class:
package test.action;import java.util.ArrayList;import java.util.List;import test.model.User;import com.opensymphony.xwork2.ActionSupport;public class TestAction extends ActionSupport {private static final long serialVersionUID = 2752911709036089235L;private int num;private List
userList;public String testNumber(){num = 56466126;userList = new ArrayList
();userList.add(new User("Mike",4546645));userList.add(new User("Sam",2389469));userList.add(new User("Keven",8923741));return SUCCESS;}//getter and setterpublic int getNum() {return num;}public void setNum(int num) {this.num = num;}public List
getUserList() {return userList;}public void setUserList(List
userList) {this.userList = userList;}}
User. java
package test.model;public class User {private String name;private int salary;public User(){}public User(String name,int salary){this.name = name;this.salary = salary;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getSalary() {return salary;}public void setSalary(int salary) {this.salary = salary;}}
JSP: number. jsp
<%@ taglib prefix="s" uri="/struts-tags"%>
Struts. xml
/number.jsp
Other attributes of the tag:
That's all.