【问题标题】:Stripes link event triggering validation that is incorrectStripes 链接事件触发验证不正确
【发布时间】:2010-06-09 13:45:19
【问题描述】:

我在一个带有事件属性的jsp中有条纹:链接标签:

<stripes:link href="${actionBean.context.currentStage.stripesForwardAction}"  addSourcePage="true" event="showTab2Link">

这会触发验证以触发嵌套属性:

    @ValidateNestedProperties({
    @Validate(field="county", required=true, minlength=2, maxlength=2, mask="\\d\\d"),
    @Validate(field="parish", required=true, minlength=3, maxlength=3, mask="\\d\\d\\d"),
    @Validate(field="holding", required=true, minlength=4, maxlength=4, mask="\\d\\d\\d\\d")
}) 

但是,如果它所验证的实际值不存在,但它们存在于 html 中和调试 bean 时,这会很好。 为什么条纹:链接会触发这个?
如果我将其更改为条纹:提交则很好。

谢谢,

戴夫

【问题讨论】:

    标签: java web-applications stripes


    【解决方案1】:

    它被触发的原因是stripes:submit 必须有表单中的字段,所以这些字段在表单提交时会传输到服务器。使用链接,除非您将它们添加为链接参数,否则您不会获得任何字段。

    您可以通过以下两种方法之一解决此问题,具体取决于:

    您希望在单击链接时这些字段出现在 bean 上吗?然后您需要使用参数填充链接,以便添加 GET 查询字符串样式:

    <stripes:link href="${actionBean.context.currentStage.stripesForwardAction}"  addSourcePage="true" event="showTab2Link">
    <stripes:param name="county" value="${actionBean.county}" />
    <stripes:param name="parish" value="${actionBean.parish}" />
    <stripes:param name="holding" value="${actionBean.holding}" />
    link text
    </stripes:link>
    

    另一方面,如果您的 bean 中不需要它们来处理该事件,您可以告诉您的 @ValidateNestedProperties 忽略该事件:

    @ValidateNestedProperties({
        @Validate(field="county", on="!showTab2Link", required=true, minlength=2, maxlength=2, mask="\\d\\d"),
        @Validate(field="parish", on="!showTab2Link", required=true, minlength=3, maxlength=3, mask="\\d\\d\\d"),
        @Validate(field="holding", on="!showTab2Link", required=true, minlength=4, maxlength=4, mask="\\d\\d\\d\\d")
    }) 
    

    那么验证不会在事件 showTab2Link 上运行,除非它确实被提供了。

    【讨论】:

    • 有道理,我试试看。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-24
    • 2015-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-03
    相关资源
    最近更新 更多