Results 1 to 6 of 6

Thread: referenceData problem

  1. #1
    Join Date
    May 2005
    Location
    California, US
    Posts
    735

    Default referenceData problem

    If I use referenceData in my SimpleFormController then I get the dreaded
    Neither Errors instance nor plain target object for bean name 'adminForm' available as request attribute
    The only way I've figured out how to get rid of this is to not use referenceData and instead have a showForm method and in it create a ModelAndView with 3 args:
    Code:
    ModelAndView mav = new ModelAndView(getFormView(), "adminForm",
                                                new AdminForm());
    My constructor is setting the command class:
    Code:
    public
    AdminCtlr() {
        setCommandClass(AdminForm.class);
    
        setFormView("admin");
        setSuccessView("redirect:admin_history.html");
    }
    What am I doing wrong?

  2. #2
    Join Date
    May 2005
    Location
    California, US
    Posts
    735

    Default

    Oops; I forgot the
    Code:
    setCommandName("adminForm");

  3. #3
    Join Date
    Jul 2005
    Location
    Russia
    Posts
    118

    Default

    you should use formBackingObject() method for the creation of your command class instance

  4. #4
    Join Date
    May 2005
    Location
    California, US
    Posts
    735

    Default

    Quote Originally Posted by EndlessWinter
    you should use formBackingObject() method for the creation of your command class instance
    Ok, thanks.

    So what's happening when I do
    Code:
    ModelAndView mav = new ModelAndView(getFormView(), "adminForm",
                                                new AdminForm());
    Why does that cause my command object to not get its data added to it on the form submit?

    I feel like I'm writing code on Perl, where there are 25 different ways to do the same thing, but unlike Perl, only 1 way (or a few ways) works. But figuring out the one true way is like solving a puzzle.

  5. #5
    Join Date
    Jul 2005
    Location
    Russia
    Posts
    118

    Default

    because prior onSubmit Spring binds to the object, that was created in formBackingObject() method. This object is different from the one you created yourself here:
    ModelAndView mav = new ModelAndView(getFormView(), "adminForm",
    new AdminForm());

    by default formBackingObject creates your command's class instance using reflection.
    There is quite a decent method flow description in Spring javadoc

  6. #6
    Join Date
    May 2005
    Location
    California, US
    Posts
    735

    Default

    Ah, ok. Thanks.

Posting Permissions

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