aspose file tools*
The moose likes Struts and the fly likes DynaValidatorForm and Wizards Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "DynaValidatorForm and Wizards" Watch "DynaValidatorForm and Wizards" New topic
Author

DynaValidatorForm and Wizards

dave sag
Ranch Hand

Joined: Feb 17, 2003
Posts: 47
I have some question srelating to DynaValidatorForms and Wizards.
  • I understand there is a bug in Struts1.1 which prevents you from using the same DynaValidatorForm for each page pf your wizard. is that correct?
  • I have defined 5 form-beans in my struts-config.xml representing pages 1 to 5 of the wizard. Is this right or i there a way to just define a single form and spread it out over many pages?
  • what is the preferred way to pre-set some of the field values in later pages of the wizard based on entries in earlier pages of the wizard? should I keep a map of the various form beans that make up my wizard and then for specific pages that need custom reseting just subclass the DynaValidatorForm and overload the reset method. if i do this do i need to call super.reset()
  • what is the mapping parameter used for exactly. got any examples of this?
  • what would cause my DynaValidatorForm to throw a NullPointerException in it's validation method?

  • Thanks in advance
    dave


    JSF / Jini / Javaspaces / JDO - all rock in my opinion.
    dave sag
    Ranch Hand

    Joined: Feb 17, 2003
    Posts: 47
    further to my question on the NullPointerException: here is some more detail.
    Dan Allen
    Author
    Ranch Hand

    Joined: Mar 05, 2003
    Posts: 164
    Yes, there is a bug in struts 1.1 that makes using the page attribute useless. The patch however is quite simple and you can just copy the source code to the DynaValidatorForm, make a MyDynaValidatorForm and apply the few lines that are changed (check bugzilla for the changes).
    You don't need multiple form beans for your multipages (in fact you don't want this). Instead, you should just use one form bean with nested properties. If you make a property like
    member.address.city
    it will automatically create the nested objects required. However, either in your reset() or in your model bean you have to initialize each nested object with a default constructor. So you would need
    public class Member implements Serializable
    {
    Address address = new Address();
    }
    then when you save the form it automatically fills in the nested objects.
    So what you refer to in validation.xml as
    member.address.city
    member.address.state
    actually maps to a real java object nesting when the form posts (which is why using ActionForms rocks so much). It is good first to practice using real ActionForms, then you can move on to DynaValidatorForms.
    good luck!


    Dan Allen | http://mojavelinux.com | Author of Seam in Action - http://mojavelinux.com/seaminaction
    dave sag
    Ranch Hand

    Joined: Feb 17, 2003
    Posts: 47
    That's very cool. I presume in that case that if I am using a DFVB in my reset method I simply call

    to initialize that address object, and just cast appropriately.
    wow that really simplifies things.
    dave sag
    Ranch Hand

    Joined: Feb 17, 2003
    Posts: 47
    oh and in answer to my own question from the top, the null pinter exception was due to my declaring a property in validation.xml that did not require any validation. if it does not need validation and you put it in there you get the NPE. silly but true.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: DynaValidatorForm and Wizards