如何在struts 2框架中验证select标签

发布于 2024-08-11 09:29:06 字数 647 浏览 1 评论 0原文

我是编程新手,目前担任初级程序员。 我目前在验证其中一个表单中的选择标签时遇到一些问题。 我实际上想做的是确保在用户提交表单之前选择一项。

以我有的形式;

<s:select list="assessmentTypes" headerKey="0" headerValue=" -- Select One --"
          listKey="id" value="name" listValue="name" key="course.assessmenttype"
          name="assessmenttype.id"/>

我对验证有一些了解,但不确定如何对选择列表进行验证。

我尝试对字符串使用普通验证,但我认为在这种情况下不需要它。例如;

<field name="course.assessmenttype">
    <field-validator type="requiredstring">
        <message>Please Select a value</message>
    </field-validator>
</field>

我们将不胜感激所有帮助,提前致谢。

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 .

In the form i have;

<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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笑脸一如从前 2024-08-18 09:29:06

一种选择是使用设置了最小值的 int 验证器。因为你想要任何大于 0 的值。

     <field name="course.assessmenttype">
          <field-validator type="int">
              <param name="min">1</param>
              <message>Please Select a value to continue</message>
          </field-validator>
      </field>

One option is to use an int validator with a min value set. Since you want any value greater than 0.

     <field name="course.assessmenttype">
          <field-validator type="int">
              <param name="min">1</param>
              <message>Please Select a value to continue</message>
          </field-validator>
      </field>
尐籹人 2024-08-18 09:29:06

将 headerKey="0" 设置为 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>

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>
格子衫的從容 2024-08-18 09:29:06
<field name="course.assessmenttype">  
           <field-validator type="regex">  
       <param name="expression">assessmentTypes</param>  
       <message>Select a value to continue</message>  
     </field-validator>  
      </field> 
instead of assessmentTypes, you can directly mention the dropdown list values. Make sure that your validator XML file is in the format <ActionClassname>-validation.xml,which should be in the same package as Action class 
<field name="course.assessmenttype">  
           <field-validator type="regex">  
       <param name="expression">assessmentTypes</param>  
       <message>Select a value to continue</message>  
     </field-validator>  
      </field> 
instead of assessmentTypes, you can directly mention the dropdown list values. Make sure that your validator XML file is in the format <ActionClassname>-validation.xml,which should be in the same package as Action class 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文