2 Replies Latest reply on Feb 24, 2009 11:40 AM by bobgee

    Best practice? - table default values, form with not all entity members

      Hi everybody,

      this is my first post in this forum.
      I'm on the beginner steps with Seam. I was working before some years with JSPs, taglibs and an own framework, a bit with MyFaces.

      I have a second form (beside the seam generated) for editing only some members of an entity.
      Since the members which are not present in the form and are defined with @NotNull obviously I get Nullpointerexecption on submitting if I don't write my own action handler.

      What is the best practice to handle table column default values?
      - first: in defining the entity - there is no annotation for a default value (only that "ugly way" with a - proprietary - DDL part using columnDefinition) and I don't want to set the default column manually at db level; I want the table to be generated by Hibernate (hibernate.hbm2ddl.auto = "update")
      - secondly: in form/action handling?

      Thanks!
      Robert
        • 1. Re: Best practice? - table default values, form with not all entity members
          jkronegg

          Since your form may be specific to a given .xhtml page, I would add in my xxx.page.xml the following (assuming your form uses the object defined by myEntityHome.instance) :


          <action execute="#{myBean.initializeMyDefaultFields(myEntityHome.instance)}"/>
          



          Then add your bean the initializeMyDefaultFields method:


          public void initializeMyDefaultFields(MyObject instance) {
            instance.setMyField("myDefaultValue");
            ...
          }
          


          • 2. Re: Best practice? - table default values, form with not all entity members

            Gruezi, Julien,


            thanks for your hint! I wasn't aware of this possibility.


            action - EL method expression that will be invoked before the page renders


            Well, I'm not surely understanding the life cycle.
            I want to create the new (persistent?) object on submitting the form not when I render the form for entering data for the new object.
            To be sure:
            Is that instance from your code fragment the same object that will be persisted on submit?


            Thanks!
            Robert