Struts 和 ValidatorForm -->它适用于可变数量的表单元素吗?
您好,
我有一个表单,可以生成多行输入元素(使用 JavaScript)供用户输入数据。每行包含有关用户输入的特定框的数据(例如高度、宽度、长度等)。我已经成功地使该表单正常工作,并且我可以从 ActionForm 读入/读出 ArrayList 对象。
我想验证这些条目以预先捕获无效条目。 (我是10年3月1日) 我似乎找不到任何有关将 ValidatorForm 与动态数量的表单元素一起使用的文档。就是永远不知道会输入多少行框,不知道有没有人成功使用Validator来验证动态表单元素?
这可能吗?或者我辞职去实现 .validate() 方法?
是否可以对某些元素使用 Validator,而将其余元素留给 .validate() 方法?有人这样做过吗?如果是的话,有什么陷阱?
我很感激您的评论,甚至是我可以阅读的资源的指针。
HI,
I have a form where I generate rows of input elements (using JavaScript) for users to enter their data. Each row contains data about a particular box that the user is entering (e.g. height, width, length, etc.). I've successfully gotten this form to work and I can read from the ActionForm into/out of an ArrayList object.
I'd like to validate these entries to catch invalid entries up front. (I'm on 1.3.10)
I can't seem to find any documentation about using ValidatorForm with a dynamic number of form elements. That is, I never know how many rows of boxes will be entered, and I wonder if anyone has successfully used Validator to validate dynamic form elements?
Is this even possible? Or am I resigned to implement the .validate() method?
Is it possible to use the Validator for some elements and leave the rest to the .validate() method? has anyone done this, and if so, what are the pitfalls?
I'd appreciate your comments or even a pointer to a resource where I can read up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过执行以下步骤来做到这一点。
1.定义一个类(简单的POJO)比如DimensionBean;其中包含一行输入元素的值(如高度、宽度、长度等)。
2. 在 Form bean(ValidatorForm 的子级)中,定义 DimensionBean 的数组或列表。数组的名称是arrDimensionBeans。
3. 在validation.xml 中,您可以如下定义它。
仅当宽度为空或高度不为空时,才会检查高度。您可以根据您的要求更改 var 值。希望这将帮助您解决您的问题。
You can do this by making following steps.
1. Define a class (simple POJO) say DimensionBean; which contains the value of one row input elements (like height, width, length etc).
2. In your Form bean (child of ValidatorForm), define an array or list of DimensionBean. The name of the array is arrDimensionBeans.
3. In your validation.xml you can define it as follows
This will check height only if width is null or height is not null. You can change the var-value as per your requirement. Hope this will help you to solve your problem.