Discussions

Web tier: servlets, JSP, Web frameworks: Struts validator plugin help needed URGENTLY .!!!

  1. Struts validator plugin help needed URGENTLY .!!! (5 messages)

    Hello to al struts users.

    I am facing somewhat unusual problem.The cuurent project is being built on struts 1.1
    All the validations were earlier done is ACTIONFORMS.for good application architecture we have decided to go for StrutsValidator/ Validator plugin which will take care of all the validations.

    All common validations are being done using the validation.xml and validator-rules.xml.
    (minlength, maxlength, email, required)
    for customised validation we have made validation-custom.xml and validator-custom-rules.xml.
    (field comparison etc)

    I have removed the Validate() from the ActionForm and set validation=false in the action mapping of struts-config.xml(This was done later as we thought setting to true invoked the validate().So we set it to validate=false, inorder to invloke the plugin).When the application starts-up the digestor reads the xml files and hold the validation in struts memory.All the error messages are given in the resource file.But we don't understand the validation is not occuring.We believe struts is not able invoke and passe it to the plugin.

    Below is an extract from the struts-config.xml.The Tiles plugin works just fine ..but Validator plugin does not work at all.

    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
           <set-property property="pathnames"
    value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml,/WEB-INF/validat
    ion-custom.xml,/WEB-INF/validator-custom-rules.xml"/>
       </plug-in>


       <plug-in className="org.apache.struts.tiles.TilesPlugin" >
           <set-property property="definitions-config"
                        value="/WEB-INF/tiles-defs.xml" />
           <set-property property="definitions-debug" value="1" />
           <set-property property="definitions-parser-details" value="0" />
           <set-property property="definitions-parser-validate" value="true" />
       </plug-in>



    Any ideas from your guys...?

    Help is appreciated.

    thanx
    Vijay
  2. With the Validator framework, regular ActionForm's won't work. Your ActionForm should extend either ValidatorForm or ValidatorActionForm. (You will still need to set validate to "true" for the ones that you wish to validate).

    Or bettery yet, switch to 1.1's Dynamic Action Forms.

    Chuck Cavaness
    Author of Programming Jakarta Struts (O'Reilly)
  3. Hi,

    Thank you for replying.I tried doing all that you suggested.
    1.Extending Actionform to both ValidatorActionForm and ValidatorForm
    2.Changed the validate = true
    3.Used DynaActionForm

    All the possible combination were checked keeping in mind the correctness for struts design compatibility.But still, I something is going wrong somewhere and the validator plugin is not getting invoked.

    Can you please pass your experience comments on this.

    Thanx
    Vijay.K
  4. I should have asked you which version of Struts you are using. I'm assuming it's 1.1b?, but have you tried the latest nightly build and still the same problem?

    Let me also ask these questions:

    1. Which container (Tomcat, WebLogic, etc...)?
    2. When the container starts up, do you see the Validator debug/info statements being printed out?

    3. Could it be that validation is taking place, but you are not seeing any errors (are you using the html:errors tag)?

    Just some ideas.

    Chuck
  5. Hi again..

    My environment is
    - struts 1.1b2
    - Weblogic 7.0
    - Maven/ant for building

    Yes when weblogic starts,it does recognise the validator plugin as the custom validation XML file which I have created gets printed on the console along the custom RULE:IDENTICAL and the related class name assigned to perform validation

    Here is the log generated out of struts...
    -----------------------------------------------------------
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG util.RequestUtils - Creating new DynaActionForm instance of type 'org.apache.struts.action.DynaActionForm'
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG util.RequestUtils - --> DynaActionForm[dynaClass=maintainPasswordLevel1Form,confirmNewPassword=<NULL>,oldPassword=<NULL>,newPassword=<NULL>]
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG action.RequestProcessor - Storing ActionForm bean instance in scope 'request' under attribute key 'maintainPasswordLevel1Form'
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG action.RequestProcessor - Populating bean properties from this request
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG beanutils.BeanUtils - BeanUtils.populate(DynaActionForm[dynaClass=maintainPasswordLevel1Form,confirmNewPassword=<NULL>,oldPassword=<NULL>,newPassword=<NULL>], {confirmNewPassword=[Ljava.lang.String;@5043cf, oldPassword=[Ljava.lang.String;@13e3d0, newPassword=[Ljava.lang.String;@51a0c9})
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG beanutils.BeanUtils - setProperty(DynaActionForm[dynaClass=maintainPasswordLevel1Form,confirmNewPassword=<NULL>,oldPassword=<NULL>,newPassword=<NULL>], confirmNewPassword, [])
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG beanutils.ConvertUtils - Convert string '' to class 'java.lang.String'
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG beanutils.ConvertUtils - Using converter org.apache.commons.beanutils.converters.StringConverter@4709fa
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG beanutils.BeanUtils - setProperty(DynaActionForm[dynaClass=maintainPasswordLevel1Form,confirmNewPassword=,oldPassword=<NULL>,newPassword=<NULL>], oldPassword, [])
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG beanutils.ConvertUtils - Convert string '' to class 'java.lang.String'
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG beanutils.ConvertUtils - Using converter org.apache.commons.beanutils.converters.StringConverter@4709fa
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG beanutils.BeanUtils - setProperty(DynaActionForm[dynaClass=maintainPasswordLevel1Form,confirmNewPassword=,oldPassword=,newPassword=<NULL>], newPassword, [])
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG beanutils.ConvertUtils - Convert string '' to class 'java.lang.String'
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG beanutils.ConvertUtils - Using converter org.apache.commons.beanutils.converters.StringConverter@4709fa
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG action.RequestProcessor - Validating input form properties
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG action.RequestProcessor - No errors detected, accepting input
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG action.RequestProcessor - Looking for Action instance for class com.mypackage.login.MaintainPasswordLevel1Action
    117125 [ExecuteThread: '11' for queue: 'default'] DEBUG action.RequestProcessor - Creating new Action instance
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - getMessage(en_US,errors.header)
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - loadLocale(en_US)
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - loadLocale(en)
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - loadLocale()
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - getMessage(en_US,errors.footer)
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - loadLocale(en_US)
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - loadLocale(en)
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - loadLocale()
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - getMessage(en_US,errors.prefix)
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - loadLocale(en_US)
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - loadLocale(en)
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - loadLocale()
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - getMessage(en_US,errors.suffix)
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - loadLocale(en_US)
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - loadLocale(en)
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - loadLocale()
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - getMessage(en_US,error.3019.308)
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - loadLocale(en_US)
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - loadLocale(en)
    117937 [ExecuteThread: '11' for queue: 'default'] DEBUG util.PropertyMessageResources - loadLocale()
    ------------------------------------------------------------
    My struts-congif.xml is in my first posting.I wanted to check if validator is ever getting invoked as I tested sending null to the default validation.xml file which contains the 'required' rule for the respective field.But if u see carefull above , its saying << Convert string '' to class 'java.lang.String' >>. I really wonder whats happening. Its says no validation error.!!!!

    If the default validation is not working then its for sure that the custom validation XML file is never invoked.

    Also If you see the value="validation.xml" in the plugin property of validator I have passed my custom XML file.One question here how does struts know that for this field I have to use the custom-validation.xml and not the validation.xml file...!! very intriguing indeed.

    Thank you ..again
    Kind Regards
    Vijay
  6. not displaying messages[ Go to top ]

    hi chuck, I am facing a similar problem. I know for sure that on m y jsp validation is taking place , but i am not able to see the error messages on my jsp. my any help greatly appreciated thanks