Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    isOneOfValidator not working on custom editor/object

    Hi,

    SC_SNAPSHOT-2010-10-24/EVAL Deployment

    I think there might be a problem with the following:

    We have our own simpletype, linked with a custom editor and java object.
    I have defined a "isOneOf" validator on my field (in the datasource xml).

    The validation is always failing which, when you think of it, is normal...
    Because how is the validator going to know which variable in my java object to validate against?!?

    Code:
    <DataSource ID="106" dropExtraFields="true" sparseUpdates="true">
    <fields>
    <field sraId="422" name="id" title="Id" canEdit="false" type="integer" primaryKey="true" defaultValue="-2000000" crud="2" >
    </field>
    
    <field sraId="15" name="defaultDistanceUnitEnumID" title="default Distance Unit EnumID" type="silkEnum" javaClass="outpost.parameter.SraEnum" crud="15" >
    <valueMap>
    <value ID="165">Km</value>
    <value ID="166">Mls</value>
    <value ID="167">Hours</value>
    </valueMap>
    <validators>
    <validator clientOnly="true" stopIfFalse="true" type="isOneOf"
    errorMessage="Value is not in list" />
    </validators>
    </field>
    </fields>
    </DataSource>
    Code:
    public class SraEnum implements Serializable {
    
      private Integer enum_id = DBConstants.NULL_INT;
      private Integer attributeType = DBConstants.NULL_INT;
      ...
    }
    Code:
    public class SilkEnumEditor extends ComboBoxItem {
    
    	}
    Code:
    [
        {
            invalidateCache:false, 
            data:{
                leasingCompanies:[
                    {
                        defaultDistanceUnitEnumID:{
                            attributeType:127, 
                            dataType:9, 
                            enum_id:166
                        },                      
                        id:100001
                    }
                ], 
                sessDtoId:100001
            }, 
            status:0, 
            isDSResponse:true
        }
    ]
    Last edited by bade; 26 Oct 2010, 09:17.

    #2
    You seem to have answered your own question - the isOneOf validator should not be used with a non-atomic type. You will need to add an equivalent custom validator.

    Comment


      #3
      Could you point me in the direction of an example of custom validator?

      Thanks

      Comment


        #4
        http://www.smartclient.com/smartgwtee/showcase/#validation_dmi
        http://www.smartclient.com/smartgwtee/showcase/#validation_velocity

        Comment


          #5
          Actually, do any of the built in validators work with custom SimpleTypes?


          Example: set a field on a DynamicForm required, then do validate().
          Nothing happens. Very likely because there is some expression that evaluates the getValue() of the field against null?
          That is never going to happen with a SimpleType (I assume) because that getValue() returns a JavaScript object.

          Can we overwrite the points where the built in required validator checks its value, or do we need to create our own Validator (either client side or server side)?

          Comment


            #6
            Yes, the built-in validators in general work with SimpleTypes. Look at the Validator method signature - the value of the field is passed, so the built-in validators have no confusion about which value is being validated.

            Comment

            Working...
            X