0

I am not sure if ScriptAssert can be applied on Field. I am trying the below ScriptAssert but all the time it returns the message "Value is Mandatory" even the _this.OBJSTATE != 'CANCELLED'. Can someone please help??

<?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>

1 Answers1

0

ScriptAssert should be applied to class level

<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>