在xml中编写椭圆形验证

时间:2015-02-22 03:54:22

标签: xml oval

我正在尝试在MVEL表达式语言的OVAL XML配置文件中编写以下java Assert语句的等价物。但我无法这样做。任何帮助将不胜感激。

public class BusinessObject 
{
   // mailingAddress must either be the delivery address or the invoice address 
   @Assert(expr = "_value ==_this.deliveryAddress || _value ==  this.invoiceAddress", lang = "groovy")

   public String mailingAddress;
}

xml ..

<class type="BusinessObject" applyFieldConstraintsToSetters="true" overwrite="false">
    <field name="mailingAddress">
        <assert lang="mvel" expr="_value ==_this.deliveryAddress || _value ==  this.invoiceAddress" message="mailingAddress must either be the delivery address or the invoice address ">
        </assert>
    </field>

1 个答案:

答案 0 :(得分:0)

这应该有效:

<class type="BusinessObject" applyFieldConstraintsToSetters="true" overwrite="false">
   <field name="mailingAddress">
       <assert lang="mvel" message="mailingAddress must either be the delivery address or the invoice address">
           <expr>_value ==_this.deliveryAddress || _value ==  this.invoiceAddress</expr>
       </assert>
   </field>
</class>

另见https://sourceforge.net/p/oval/code/HEAD/tree/trunk/src/test/resources/net/sf/oval/test/validator/XMLConfigurationTest.xml