Struts ActionForm属性应该是什么类型的? [英] What type should Struts ActionForm properties be?
问题描述
此外,似乎如果一个属性是Integer类型,而且用户输入的值不是一个整数值,Struts会静静地吞下这个并且不设置属性。这是什么?
对于Struts 1.2x,用户在HTML表单上输入或选择值的属性由Struts HTML标签自动填充在ActionForm实例上必须是字符串或布尔值。然而,没有理由为什么你的ActionForm不能有getter方法返回属性作为更有意义的类型为您的应用程序例如日期。
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a specific question regarding ActionForms. Some of them have only String properties (even for numbers), some of them use the seemingly appropriate types (Integer, Date, String, etc). What's the best practice here?
Also, it seems that if a property is of type Integer, and the value the user entered is not an integer value, Struts silently swallows this and just doesn't set the property. What's up with this?
For Struts 1.2x, properties where the user enters or selects values on the HTML form and that are populated on the ActionForm instance automatically by the Struts HTML tags must be Strings or booleans. However, there's no reason why your ActionForm can't have getter methods that return the properties as more meaningful types for your application e.g. Date.
这篇关于Struts ActionForm属性应该是什么类型的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!