Struts ActionForm属性应该是什么类型的? [英] What type should Struts ActionForm properties be?

查看:170
本文介绍了Struts ActionForm属性应该是什么类型的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了这个巨大的遗留Java Web应用程序使用Struts 1.2.4。我有一个关于ActionForms的具体问题。其中一些只有String属性(即使是数字),其中一些使用看似合适的类型(整数,日期,字符串等)。这里最好的做法是什么?



此外,似乎如果一个属性是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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆