Results 1 to 6 of 6

Thread: New or Edit state check on validation from controller

  1. #1
    Join Date
    Aug 2004
    Location
    San Jose, CA
    Posts
    24

    Default New or Edit state check on validation from controller

    The objects that I use as form-backing objects in my controllers don't get Id's until they are saved to the database. However, I'm having trouble validating from my controllers whether a null Id is an error or it's just an unsaved object. I don't really want to put an isNew method on my form-backing objects. Has anyone else overcome such an issue? Am I missing something?
    Thanks in advance.

    - Justin

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    335

    Default

    Insted of using null why not use 0 or -1 as the id for new objects? Then you can be sure that a null id is an exception.

  3. #3
    Join Date
    Aug 2004
    Location
    San Jose, CA
    Posts
    24

    Default Erroneous null

    But then how do I determine if some other code has erroneously nulled (or zeroed, or negative-oned) my Id?

  4. #4
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    But then how do I determine if some other code has erroneously nulled (or zeroed, or negative-oned) my Id?
    I would ask the same question about the logic behind isNew!!!

    Hibernate uses the unsaved-value paradigm. If some code changes accidently the value of the object' id, this is the responsability of this code!!!

    I think this is a clean and less-intrusive solution.
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  5. #5

    Default

    You can add your isNew object to the model in the referenceData method so you won't need to include it in your command object.

  6. #6
    Join Date
    Aug 2004
    Location
    Denver
    Posts
    249

    Default Re: New or Edit state check on validation from controller

    My id's are usually not exposed to the user, but rather as a hidden field in a form. When the record is new, the id of my POJO (a Long) is set to null - when it's an existing record, it's not. I doubt your issue is that simple, but it's worth a shot.

Similar Threads

  1. Replies: 17
    Last Post: Jan 2nd, 2007, 01:43 PM
  2. Replies: 4
    Last Post: Jun 30th, 2005, 11:28 PM
  3. Replies: 1
    Last Post: Apr 27th, 2005, 07:46 AM
  4. Replies: 2
    Last Post: Apr 27th, 2005, 12:30 AM
  5. Commons validation with wizard form controller
    By brianstclair in forum Web
    Replies: 0
    Last Post: Jan 14th, 2005, 02:14 PM

Posting Permissions

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