Need to check userid existence with struts 2

半世苍凉 提交于 2019-12-08 18:20:28

You can add fieldexpression validator to the field. The value returned by DAO should be placed to the value stack. It's easy if you create a getter in the action class and return the value.

action class:

public boolean getMyBoolean(){
  return myDAO.getMyboolean();
}

-validation.xml:

<field name="Email">
    <field-validator type="requiredstring">
        <message>Email is required</message>
    </field-validator> 
    <field-validator type="email">
        <message>Please enter valid email id</message>
    </field-validator>
    <field-validator type="fieldexpression">
        <param name="expression"><![CDATA[myBoolean == false]]></param>
        <message>email exists in db</message>
    </field-validator>
</field>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!