简体   繁体   English

如何防止在Struts2 textfield标记中显示默认值“0”

[英]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. 当我用数据填充它时,有一些整数文本字段显示'0',这是整数的默认值。 I want the textfield to be blank than a zero. 我希望textfield为空而不是零。

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

Please help. 请帮忙。

You need to use Integer class and not int for that. 您需要使用Integer类而不是int int will always be initialized to 0. S2 OGNL and type convertor will take care of type conversion for you. int将始终初始化为0. S2 OGNL和类型转换器将为您处理类型转换。

For Integer default will be null and it will solve your issue. 对于整数,默认值为null,它将解决您的问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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