Announcement

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

    Server-side validation questions

    Hello,

    We are going to be implementing server-side validations and I'm looking for some clarification.

    1. If we have a custom javascript validator like the snippet below, how would we configure or write the accompanying server-side validation logic for this validator using SmartClient's Validator? Obviously, we know how to write the java to check this same validation logic. But, the goal would be to configure and write custom validation logic for both client-side and server-side in one common place such as the Datasource definition files. Can you shed any light on how that would work or point me to the releveant docs?

    Code:
                       <validator type="custom" >
                     <condition><JS><![CDATA[
        			function (item, validator, value) {
        				if( item!=null && item.form!=null){
    				      	if(value==0 || value > 999 || value < -999){
    				      		return false;
    				      	}
        				} 
        				return true;
        			}
    				]]></JS>
    				</condition>
                     <errorMessage>
                     	<spring:message code="prompt.fa.betafixvalidation"/>
                     </errorMessage>
                     </validator>

    2. We have a separate component that runs nightly to import data into our database from external sources. We'd like to apply the same validators to this process even though it is currently not integrated at all with SmartClient. So, how would this work? Is it simply a matter of installing the SmartClient server components as part of this batch process and wiring it up to call the same validators?

    3. We are investigating Hibernate validator as well (http://www.hibernate.org/412.html). Would that work as a replacement for SmartClient server-side validation or an enhancement? Or, would it just end up creating a lot of duplicate validation work?

    Our ultimate goal is to have one common repository of validator logic and configuration that can be applied in several different places including custom validators for SmartClient client-side javascript, SmartClient server-side java logic, and additional components that also import data into our database.

    #2
    1) The general recommendation is to override the server-side DataSource.validate() to return custom errors. Common validators can be added to a utility class.

    We're also looking at hooks that would allow you to add named server-side validators that you can then just declare in your .ds.xml just like the built-in validators.

    2) Yes, that's what you would do.

    3) There'd be no reason to replace the built-in validators (that would just be extra work), but it might make sense to build a DataSource subclass where you can declaratively activate certain Hibernate-based validators via the approach from #1 above.

    Comment


      #3
      We're also looking at hooks that would allow you to add named server-side validators that you can then just declare in your .ds.xml just like the built-in validators.
      Are those hooks available yet? If so, can you point me to where I can find out more about them?

      Comment


        #4
        You can create a validator of type "serverCustom" and set a serverCondition that's a Velocity template, with access to lots of likely objects for performing validation.

        Other than that, approach #1 still applies, except that's it's now possible to add custom properties to your DataSources/DataSourceFields in your .ds.xml file and access them via getProperty(), which makes it possible to be more data-driven (build a generic DataSource and enable features via flags).

        It's not currently possible to declare a set of resuable server-side validators across different DataSource types.

        Comment

        Working...
        X