Performance of Validator Plugin in Server Side Form Validation

Question:  How validator plug-in is performing server side form validation in our Struts-apps (explain flow)

  • Form page submits the request to struts applications
  • ActionServlet traps and takes the request and also reads the form data of form page
  • ActionServlet writes formdata to form bean class properties of form bean class object by calling setxxx () method
  • ActionServlet calls validate () method of our form bean class object since it is not available the super class validate () method will be execute
  • This super class validate () method activator plug-in (validate form class)
  • This validator plug-in uses the entries of validation.xml file to know the validator rules that are applied on form bean properties.
  • Validator plug-in performs form validation on form bean properties data

                 Validation errors are there                                                     No-Validation errors

  • Super class validate (-,-) returns                                    Super class validate (-,-) returns Action-Errors
  • Action-Error class object with elements (size>0)         class object without elements (size = 0).

ActionServlet forward the control to input.jsp program to display validation error messages.

When <arg> tag is used with validator rule name then that <arg> tag supplies argument value of only that validator rule related error message.

  •        <field properties = “password” depends = “required, maxlength”>
  •          <arg position = “0” name = “required” key = “my.pass”/> -> Supplies {0} valiue for required rule related form validation error messages.
  •          <arg position = “0” name = “maxlength” key = “my.pass1”/> -> Supplies {0} valiue for maxlength rule related form validation error messages.
  •             —————-
  •              —————–
  •       </field>

When <arg> tag is used without validator rule name then that tag can supply argument value for multiple values rule form validation error messages.

Example:- 

  • <field properties = “password” depends = “required,maxlength”>
  •                 <arg position = “0” key = “my.pass”/>
  •                         ————-
  •                         ————-
  •  </field>

In the above code my.pass supplies {0} value for required, maxlength validator rules related error messages.

  • Code in validation.xml to apply required, maxlength validation rules on password form bean property.

In validation.xml

  •   <field property = “password” depends = “reauired, maxlength”>
  •        <arg position = “0” name = “required” key = “my.pass”/>
  •         <arg position = “0” name = “maxlength” key = “my.pass1”/>
  •         <arg position = “1” name = “maxlength” key = “$ {var: maxlength}” resource = “false”/>
  •       <var>
  •        <var-name> maxlength </var-name>
  •         <var-value> 10 </var-value>
  •        </var>
  •    </field>
  • If you have not liked the default error msg of validator rules then we can configure user defined messages as form validation error messages by using <msg> tag in validation.xml file. In this situation if any other than {0} value is required for validator rules as input values then they must be supplied by using <arg> tag.

Leave a Reply

Your email address will not be published. Required fields are marked *