如何在 struts 2 框架中验证选择标签 [英] How to validate a select tag in struts 2 framework
问题描述
我是编程的新手,目前我是一名初级程序员.我目前在验证其中一种表单中的选择标签时遇到了一些问题.我真正想做的是确保在用户提交表单之前选择了一项.
I am a newbie into programming and i am currently employed as a junior programmer. I am currently having some problems validating the select tags in one of my forms. What i actually trying to do is to ensure that one item is selected before the user submits the form .
以我有的形式;
<s:select list="assessmentTypes" headerKey="0" headerValue=" -- Select One --"
listKey="id" value="name" listValue="name" key="course.assessmenttype"
name="assessmenttype.id"/>
我有一些验证知识,但不确定如何为选择列表执行此操作.
I have some knowledge of validation but not to sure how to do it for the select list.
我尝试对字符串使用普通验证,但我认为在这种情况下不需要它.例如;
I tried using a normal validation with strings but i don't think it is required in this case. for example;
<field name="course.assessmenttype">
<field-validator type="requiredstring">
<message>Please Select a value</message>
</field-validator>
</field>
感谢所有帮助,提前致谢.
all help would be appreciated, Thanks in advance.
推荐答案
将 headerKey="0" 设置为 headerKey=""
Set headerKey="0" to headerKey=""
<field name="course.assessmenttype">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>Please Select a value to continue</message>
</field-validator>
</field>
这篇关于如何在 struts 2 框架中验证选择标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!