Announcement Announcement Module
Collapse
No announcement yet.
New or Edit state check on validation from controller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      Erroneous null

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

      Comment


      • #4
        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.

        Comment


        • #5
          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.

          Comment


          • #6
            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.

            Comment

            Working...
            X