How to validate a boolean in Struts 2 Validation Framework

帅比萌擦擦* 提交于 2019-12-13 01:19:32

问题


Simple: I have to be sure the privacy checkbox on my form is checked. I tryed to use the expression validator (and the fieldexpression validator) but it does'n work. Can anobody help me?


回答1:


Can you provide more information? How were you using the expression validator, and why didn't it work? Seems like that approach should work fine.

A few things to consider: do you have both a "getter" and a "setter" method for your boolean? Do you have both the "validation" and the "workflow" interceptors in your interceptor stack (the "defaultStack" does, for example).




回答2:


This worked for me:

<field name="agreeToPrivacy">
    <field-validator type="expression" >  
    <param name="expression">agreeToPrivacy == true</param>  
            <message>You must agree to the privacy agreement to continue.</message>  
    </field-validator>
</field>


来源:https://stackoverflow.com/questions/3663457/how-to-validate-a-boolean-in-struts-2-validation-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!