SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Struts Validator with DynaValidatorForm

    I have a database persistent object which I wish to maintain. I have something like the following setup:

    Actions
    1 - LoadObjectABCAction for loading the object. The action specifies a formbean of ObjectABC with session scope.
    2 - UpdateObjectActionABC which updates the object on the database. This action also specifies a formbean of type ObjectABC with session scope.

    Form Beans
    1 - ObjectABC. This is a DynaValidatorForm bean. It has a String property called name.

    Validation
    1 - A validation rule which validates the name property on ObjectABC.


    The intended process
    1 - LoadObjectABCAction gets called and struts creates a ObjectABC which gets passed in to LoadObjectABCAction and added to the session scope. Properties on this object are then populated by loading from the database.
    2 - ObjectABC is displayed for edit using a JSP page.
    3 - UpdateObjectABCAction is called and the updated ObjectABC is saved to the database.

    The problem
    The problem is that I only want the struts validator to validate ObjectABC for UpdateObjectABCAction. However ObjectABC is delclared as the formBean for LoadObjectABCAction so that struts will create the bean for LoadObjectABCAction to populate. Unfortunately this means that the validator will validate ObjectABC when LoadObjectABCAction gets called, before it gets populated with data. This means the validation will always fail.

    I could manually create the bean in LoadObjectABCAction but this defeats the object of using Dyna beans.

    Is there any way round this or do I have to scrap Dyna beans in the scenario and use a 'real' bean, which gets created in LoadObjectABCAction, rather than by Struts?

  2. #2
    SitePoint Evangelist vikrantkorde's Avatar
    Join Date
    Jun 2004
    Location
    Mumbai, India
    Posts
    541
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hav you tried associating the ObjectABC to UpdateObjectABCAction. This will invoke the validator framework on access of UpdateObjectABCAction.
    Vikrant Korde
    S Y S T I M E, Mhape,
    Mumbai, Maharashtra, India.

  3. #3
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not quite sure what you mean by associate? Do you mean set it as the form bean in the action mappings for the update? If so then it is already, the problem is that it also needs to be associated with the load action so struts create the bean. That prematurely invokes the validation.

  4. #4
    SitePoint Wizard silver trophy rushiku's Avatar
    Join Date
    Dec 2003
    Location
    A van down by the river
    Posts
    2,056
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    The validate attribute of the action tag is true by default, you must set it to false when you do not want to invoke validation for a particular action..

  5. #5
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •