2017-09-28 2 views
0

Ich bin mir nicht sicher, ob ScriptAssert auf Field angewendet werden kann. Ich versuche die folgende ScriptAssert aber die ganze Zeit gibt es die Nachricht "Wert ist obligatorisch" sogar die _this.OBJSTATE! = 'CANCELED'. Kann mir bitte jemand helfen ??Bean Validation ScriptAssert funktioniert nicht

<?xml version="1.0" encoding="UTF-8"?> 
<constraint-mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd" 
        xmlns="http://jboss.org/xml/ns/javax/validation/mapping"> 
    <default-package>x.x</default-package> 

    <bean class="x.class" ignore-annotations="true"> 
     <field name="OBJSTATE"> 
      <constraint annotation="javax.validation.constraints.Pattern"> 
       <message>Value should be CANCELLED/RELEASED</message> 
       <element name="regexp">^(CANCELLED)$|^(RELEASED)$</element> 
      </constraint> 
      <constraint annotation="javax.validation.constraints.NotNull"> 
       <message>Field is Mandatory</message> 
      </constraint> 
      <constraint annotation="org.hibernate.validator.constraints.NotBlank"> 
       <message>Value is Mandatory</message> 
      </constraint> 
     </field> 
     <field name="T1PONumber"> 
      <constraint annotation="org.hibernate.validator.constraints.ScriptAssert" > 
       <message>Value is Mandatory</message> 
       <element name="lang">javascript</element> 
       <element name="script" > 
        <value>_this.OBJSTATE == 'CANCELLED'</value> 
       </element> 
      </constraint> 

     </field> 

    </bean> 
</constraint-mappings> 

Antwort

0

ScriptAssert sollte

<bean class="x.class" ignore-annotations="true"> 
    <class ignore-annotations="false" > 
     <constraint annotation="org.hibernate.validator.constraints.ScriptAssert"> 
      <message>T1PONumber value is Mandatory</message> 
     <element name="lang">javascript</element> 
     <element name="script" > 
      <value>_this.OBJSTATE != 'CANCELLED'</value> 
     </element> 
     </constraint> 
    </class> 
    <field name="OBJSTATE"> 
     <constraint annotation="javax.validation.constraints.Pattern"> 
      <message>Value should be CANCELLED/RELEASED</message> 
      <element name="regexp">^(CANCELLED)$|^(RELEASED)$</element> 
     </constraint> 
     <constraint annotation="javax.validation.constraints.NotNull"> 
      <message>Field is Mandatory</message> 
     </constraint> 
     <constraint annotation="org.hibernate.validator.constraints.NotBlank"> 
      <message>Value is Mandatory</message> 
     </constraint> 
    </field> 
    <field name="T1PONumber"> 


    </field> 

</bean> 
auf Klassenebene angewendet werden
Verwandte Themen