Results 1 to 4 of 4

Thread: one-to-many foreign key validation using onBindAndValidate

  1. #1
    Join Date
    Apr 2005
    Posts
    3

    Default one-to-many foreign key validation using onBindAndValidate

    Dear Springers,

    Apologies for the noob question but I have been struggling with this for a day and searching the forums & lists with no luck.

    Simple situation, you've seen it a million times.

    one-many relationship between objectA and objectB, lets say Building and Apartment.

    Apartment has a formController in which a list of Building populates a dropDown.

    selecting a Building to which Apartment belongs sets a string value buildingID in the request.

    The apartmentFormController (subclass of SimpleFormController) is trying to validate the data, and throws a bindException because String buildingID is not of type Building .

    So I override onBindAndValidate to handle the binding of buildingID to Apartment.Building .

    This works OK, but the BindException is still there, so my form never calls onSubmit and instead returns the page with the error message .

    How do I get rid of the error so that I can process my form submission ?


    OR ::: is there a better way to handle bindExceptions ? Do I need to write a custom validator for EVERY field that is a foreign key ?

    many thanks for your considerations

    busquelo

  2. #2
    Join Date
    Apr 2005
    Posts
    3

    Default enclosed code sample

    maybe some code will help . am I doing something wrong here :
    Code:
     protected void onBindAndValidate(HttpServletRequest request,
                          Object command, BindException errors)
                   throws Exception {
            log.debug ("apartmentFormController::onbind, error count is: " + errors.getErrorCount());
            Apartment apt = (Apartment) command;
            String bldgId = request.getParameter("building");
            log.debug("bldgId is " + bldgId);
            apt.setBuilding(buildingManager.getBuilding(bldgId));
            log.debug ("set apt's building id, leaving method.");
                
    
        }

  3. #3
    Join Date
    Oct 2004
    Location
    Rotterdam, Netherlands
    Posts
    90

    Default

    Another approach that you might consider using is creating a custom PropertyEditor that will do the lookup for you. This is described in this thread:

    http://forum.springframework.org/viewtopic.php?t=299

  4. #4
    Join Date
    Apr 2005
    Posts
    3

    Default thank you very much, this solved my issue !

    Thanks, the custom PropertyEditor solved my issue !

    Cheeeeeeers !

Similar Threads

  1. Replies: 1
    Last Post: Aug 18th, 2006, 11:04 PM
  2. Replies: 2
    Last Post: Oct 10th, 2005, 05:12 PM
  3. Lost with Validation
    By RAPHEAD in forum Architecture
    Replies: 6
    Last Post: May 29th, 2005, 06:01 AM
  4. Replies: 1
    Last Post: Apr 15th, 2005, 05:50 PM
  5. Domain Object Validation
    By lhilden in forum Architecture
    Replies: 4
    Last Post: Dec 14th, 2004, 07:00 AM

Posting Permissions

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