1 Reply Latest reply on Jan 18, 2012 12:52 AM by william stephen

    Using CRUD with EntityHome in a LRC

    Jonne Deprez Newbie

      Just as in the seampay example, I display a list of entityHome objects on a page. The name of the items is MailImportHome. The difference between the seampay example and my application is that the list of EntityHome objects is part of a LRC.


      Using


      <s:link view="/mailImport.xhtml" value="Edit" rendered="#{!mi.miActive}">
        <f:param name="mailImportId" value="#{mi.id}"/>
      </s:link>
      
      <s:link action="#{mailImportHome.remove}" value="Remove" rendered="#{!mi.miActive}">
         <f:param name="mailImportId" value="#{mi.id}"/>
      </s:link>



      the user can edit or remove the item. On the bean the remove method is overridden, to refresh the list after the transaction.


      @RequestParameter Integer mailImportId;
      
      @Override
      public Object getId() {
        return mailImportId;
      }
      
      @Override
      public String remove() {
        String result = super.remove();
        Events.instance().raiseEvent("refreshProject");
        return result;
      }



      This works fine for the first object and it displays a message that the object is successfully deleted. But when you try to delete a second item, the first object is injected again, which results in an error. So when passing the id of the item in the remove link, Seam ignores the new value when the link is clicked a second time.
      After deleting the item, the debug pane still shows a MailImportHome item, with an empty id.
      Could this be a bug?

      The same strange behaviour appears when I click the edit link, submit the edit form with invalid values (which decorates the field with a warning) and then cancel the edit. Editing an item starts a nested conversation, clicking the cancel button will end it again. I would suspect that Seam would have forgotten the item after ending this nested conversation, but it doesn't! Again a MailImportHome with an empty id is still visible on the debug pane. Every time you try to edit another item, it injects the item that was clicked first.


      From pages.xml:


      <page conversation-required="true" login-required="true" view-id="/mailImport.xhtml">
        <description>Scheduling import of data by e-mail for #{currentProject.prjName}</description>
        <begin-conversation nested="true" />
        <navigation from-action="#{mailImportHome.saveAndSchedule}">
         <rule if-outcome="persisted">
          <end-conversation/>
          <redirect view-id="/projectDetails.xhtml"/>
         </rule>
        </navigation>
        <navigation from-action="#{mailImportHome.updateAndSchedule}">
         <rule if-outcome="updated">
          <end-conversation/>   
          <redirect view-id="/projectDetails.xhtml"/>
         </rule>
        </navigation>
        <navigation from-action="#{mailImportHome.remove}">
         <rule>
          <end-conversation/>
          <redirect view-id="/projectDetails.xhtml"/>
         </rule>
        </navigation>
       </page>



      The only link I found to a similar problem is in this thread.


      Could anyone explain me how to get CRUD behaviour in the middle of a LRC (with nested conversations) using EntityHome?