5 Replies Latest reply on Oct 9, 2007 2:56 PM by griffitm

    Create New Entity -> Page Round Trip & Update autoincrement

    griffitm

      Re: Create New Entity -> Page Round Trip & Update autoincrement

      Hello all,

      I am new to seam & JSF in general, I have searched the forum for this problem and could not find anything related. I am using an application that was generated by seamgen.

      I have an entity, called status. If I create a new status, the proper table is updated, but upon the round trip from the server, the page does not contain the autoincremented ID from the status table. Subsequently, when I try to add related information or update it without going back to the list to select it, I get an error, because the ID = 0, which of course is incorrect.

      I'm sure there must be a common way to handle this type of situation.

      I have the status id mapped as follows in my xhtml fragment:

       <s:decorate id="idDecoration" template="layout/edit.xhtml">
       <ui:define name="label">id</ui:define>
       <h:inputText id="id"
       required="true"
       disabled="#{statusHome.managed}"
       value="#{statusHome.instance.id}">
       <a:support event="onblur" reRender="idDecoration" bypassUpdates="true"/>
       </h:inputText>
       </s:decorate>
      


      Can anyone give me a push in the right direction? Ideally, I want the id field to appear as a hidden field so the user does not see it.

      I am using seam 2.0.0CR1.

      Thanks in advance,

      MG

        • 1. Re: Create New Entity -> Page Round Trip & Update autoincrem
          griffitm

          It seems as if persisting the entity is not tied to the correct instance?

          My page navigation all look as follows:

           <param name="statusFrom"/>
           <param name="statusId" value="#{statusHome.statusId}"/>
          


          The value that is tied to the HTML for, (therefor the value that I would believe to be forwarded as a parameter after the persist method is:

          <h:inputText id="id"
           required="true"
           disabled="#{statusHome.managed}"
           value="#{statusHome.instance.id}">
           <a:support event="onblur" reRender="idDecoration" bypassUpdates="true"/>
           </h:inputText>


          Am I on the wrong track here?

          Thanks in advance for any suggestions!
          MG

          • 2. Re: Create New Entity -> Page Round Trip & Update autoincrem
            saeediqbal1

            I am not good at this either, but i see at one point you call it statusId and the other one you just call it id , is this a typo?

            • 3. Re: Create New Entity -> Page Round Trip & Update autoincrem
              griffitm

              These are seamgen generated variable and class names, based on the tables that are backed by the EJB3 entity beans. If the names of the variables are wrong, its because they were generated incorrectly. I don't think that is the case. Can someone point me to a request/response cycle for SEAM? The seam reference guide states:

              You can define actions and parameters for
              a page with the view id /calc/calculator.jsp in a resource named calc/calculator.page.xml. The root
              element in this case is the <page> element, and the view id is implied:


              Is there some sort of impedance between what the convention is and what seamgen generates?

              Thanks in advance.

              • 4. Re: Create New Entity -> Page Round Trip & Update autoincrem
                griffitm

                In the struts world, I've dealt with this by getting the ID after update and explicitly updating my model with the id after the DB update. This is usually done in the struts action class.

                Is there a similar metaphor for doing this in seam? Do I need to have a stateless session bean that updates something? I am not quite sure how this would map back to my model or page parameter. I can't believe this is a difficult problem, only one where I do not know where the answer lives.

                Anyone have the same problem and overcome it? Any help would be much appreciated!

                MG

                • 5. Re: Create New Entity -> Page Round Trip & Update autoincrem
                  griffitm

                  Since I seem to be having this conversation with myself, I thought I'd post the solution so I would know what I did wrong. When I used seamgen to generate the entities

                  seam generate-entities
                  It did not properly add the @GeneratedValue annotation to the entity class for the autoincrement field in the table. I'm not sure if this is a hibernate defect, seamgen defect or user error --but it sure was looking for a needle in a haystack.