简体   繁体   中英

How to prevent the default value '0' from being shown in Struts2 textfield tag

I have a form with several textfields. When I populate it with data, there are some integer textfields which is showing '0', which is the default value for integer. I want the textfield to be blank than a zero.

<s:textfield id="txtPhone" name="phone"/>

Please help.

You need to use Integer class and not int for that. int will always be initialized to 0. S2 OGNL and type convertor will take care of type conversion for you.

For Integer default will be null and it will solve your issue.

如果该字段确实是可选的,请将字段设为Integer,因此默认值为null!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM