3 Replies Latest reply on Feb 5, 2009 1:30 PM by waltc

    extending a seam-gen CRUD application set

    waltc
      Hi, I am having the following issues when extending a CRUD application generated by seam-gen. This should be idiot-simple but I am having issues. Seam-gen generates an xxxHome and an xxxList for all the tables in the DB. I added an action which is only rendered if the value of a column in the table displayed is a certain value. This works fine. Here is that code in the xhtml file.

                  #{' '}
                  <s:link action="#{Resubmitter.resubmit}"
                         value="Resubmit"
                   propagation="none"
                   id="upddocumentResubmit"
                   rendered="#{_upddocument.updDocumentDocState==400}">
                      <f:param name="upddocumentUpdDocumentDocId"
                              value="#{_upddocument.updDocumentDocId}"/>
                  </s:link>

      This works fine. My understanding is, correct me if I am wrong, the variable upddocumentUpdDocumentDocId is created, if it doesn't already exist, and populated with the docId of the selected row. The _upddocument variable is used to iterate over the resultSet of the updDocumentList object created by seam-gen.  My understand, correct me if I am wrong, is that upon reaching this declaration:

          <rich:dataTable id="upddocumentList"
                      var="_upddocument"
                    value="#{upddocumentList.resultList}"
                 rendered="#{not empty upddocumentList.resultList}">

      an instance of upddocumentList is created, if it doesn't exist, and the _upddocument variable is assigned the resultList of the object that sweeps the table w or w/o the criteria.

      In my new action, I coded:

          @In UpddocumentHome upddocumentHome;
          @In UpddocumentupdatelogList uupddocumentupdatelogList;
          @In UpddocumentupdatelogHome upddocumentupdatelogHome;

      In order to pick up the home object for that table and a related table as well as a list object for the second table.  My assumption was that the selected row would be current in the home object. This may have been flawed logic but I received a RequiredException that upddocumentHome needed to be not null. My understanding was if it was not in existence it would have been created, either way that variable would not have come in as null. Why? Isn't it known to Seam by virtue of it scanning the jar files and recognizing the @Name in the UpddocumentHome class? So I do not understand that and I am sure the reason for it would apply to the other two objects there as well.

      I next decided that on the action the variable upddocumentUpdDocumentDocId was set in the slink and I should import it via:

          @In int upddocumentUpdDocumentDocId; This is defined as an int.


      This too failed for the same reason. So I am at a loss to understand what is happening here.

      I have written seam apps where I create the factory generating the @DataModel and that seems to work fine. In this current case I am trying to access the data from an external source.

      Thanks,

      Walt Corey
        • 1. Re: extending a seam-gen CRUD application set
          waltc
          addendum ---------

          I modified the xhtml to the following:

                      <s:link action="#{Resubmitter.resubmit(updDocumentList)}"
                             value="Resubmit"
                       propagation="none"
                       id="upddocumentResubmit"
                       rendered="#{_upddocument.updDocumentDocState==400}">
                          <f:param name="upddocumentUpdDocumentDocId"
                                  value="#{_upddocument.updDocumentDocId}"/>
                      </s:link>


          passing the actual instance of the list object up to the action bean.

              public void resubmit(UpddocumentList upddocumentList) {
                   if (upddocumentList == null) {
                        statusMessages.add(Severity.FATAL, "Upable to locate upddocumentList object");
                        return;
                   }

          Even with this the null test traps the invocation.
          I also tried using the following:

                   UpddocumentList upddocumentList = (UpddocumentList)Contexts.lookupInStatefulContexts("upddocumentList");
                   if (upddocumentList == null) {
                        statusMessages.add(Severity.FATAL, "Upable to locate upddocumentList object");
                        return;
                   }

          and all attempts are consistent, the upddocumentList object does not exist even though it is used successfully in the upddocumentlist.xhtml.

          I believe I am either doing something naively incorrect or I have to have the factory that populates that result set. I am betting on the former so any advise would be greatly appreciated.

          Thanks,

          Walt Corey
          • 2. Re: extending a seam-gen CRUD application set
            waltc
            addendum 2.....

            If I add (create=true) to the @In statements above they do get created. However, in the case of the upddocumentList object it already was created. Why are the instances created in the xhtml not visible to the action bean?

            Again, in a nutshell, here is what I am trying to do.

            I list the contents of a table (done, works fine).

            I add an additional action if one of the columns matches a certain criteria (done, works fine).

            Within the action that gets called (it does get called) I want access to the selected row (DOESN'T WORK!).

            At the bottom of the form I offer a global action to do the same processing as above but to all rows meeting that criteria (done, I believe it works fine).

            It is not clear from the Seam in Action book or looking at the xhtml why the row selected gets shown in the edit screen when 'edit' is selected as the action for a given row. A location in the List object become the active instance in the home object.  I need to get access to the same stored row in my action bean and, to date, have not.

            Could someone explain what I am missing?

            Thanks,
            Walt
            • 3. Re: extending a seam-gen CRUD application set
              waltc
              I guess for the purposes of people that run across this missive in an attempt to resolve a similar problem they may be having:

              (create=true) added to the @In does, in fact create instances of the object. What the object name is appears to be required to be the id of the object defined, be it in a @Name or in an xhtml. But the truly unintuitive thing is in the case of the <object>List object that is traversed and a row selected in the <xxx>List.xhtml is a newly 'created' <object>List injected value (@In <object>List id does infact have the knowledge of what occurred in the facelet. I know some of you readers may respond with a loud 'Duh?' but when you add (create=true) to the injection it is not obvious what gets created is a link to a pre-existing object. Remember too I said above I unsuccessfully tried "Contexts.lookupInStatefulContexts("upddocumentList")". this is an alternative to the annotative approach. Once I added the (create=true) the api call successfully found the object, presumably because it was created in the annotative method. Yet it correctly pointed to the same object used in the facelet which clearly means it didn't 'create' a new instance. This was my concern in even trying this approach. So, dear reader, why does @In EntityManager entityManager work without a new, or message object? Why isn't create=new the default? These are questions I am still left with but, for now, I am past this hurtle and look forward to bumping into the really unobvious situations that are flaws in the design of Seam.

              Walt Corey