关于struts2 服务器验证问题

关于struts2 服务器验证问题

问题描述:

业务需求:添加一条child记录。
业务分析:跳转到添加页面,填写相关属性值,选择select控件中parent的值(parent是从数据库中取),提交。
业务要求:需要服务器端验证,如果没有填写必须的属性值,返回到添加页面并且显示错误消息

add.jsp代码:
[code="java"]












您现在的位置:添加页面









method="post">


















添加信息

a:

class="text required idCard mask-int mask-special" size="12" />



b:

class="text required mask-special" />

parent:

validate="required:true">

请选择



/c:out

/c:forEach


日期:

onFocus="WdatePicker({skin:'whyGreen',isShowClear:true,readOnly:true})" />







            </div>
        </form>
    </div>
</body>

[/code]

struts.xml文件内容:
[code="java"]

 <interceptor-ref name="store">  
                <param name="operationMode">AUTOMATIC</param>  
            </interceptor-ref>  

 <action name="*Child" class="childAction" method="{1}">
        <result name="add" type="redirect">displayListChild.action</result>
        <result name="addForward">/example/add.jsp</result>
        <result name="addedForward" type="redirectAction">addForwardChild</result>
        <result name="modify" type="redirectAction">displayListChild</result>
        <result name="modifyForward">/example/modify.jsp</result>
        <result name="removeBatch" type="redirectAction">displayListChild</result>
        <result name="remove" type="redirectAction">displayListChild</result>
        <result name="displayList">/example/{1}.jsp</result>
        <result name="invalid.token">/message.jsp</result>
        <result name="input">/example/add.jsp</result>
    </action>

[/code]

在我的ChildAction类下建ChildAction-addChild-validation.xml文件

问题:
如果struts.xml文件中的/example/add.jsp是这样,如果在add.jsp页面没有填写值,会在验证,并在add.jsp页面上显示验证错误,但这样的话 就获取不到数据库中值。

如果我改成{1}ForwardChildselect有值,可验证错误消息不能显示。

我也加了

AUTOMATIC

也不行。

问问,这样的问题怎么解决!

写出来有点多, 参考我在 csdn 回复的看下吧

http://topic.csdn.net/u/20090908/15/32830894-e841-4353-9ef3-b021b69bf120.html

http://topic.csdn.net/u/20091008/16/a4bbfa1d-41d5-437f-98ad-68a92f20a933.html

LZ 用的 验证架构,应该使用 将这个下拉框单独抽出来处理