6 Replies Latest reply on Nov 16, 2006 5:01 PM by kasim

    Using the EntityHome and problems therein

    sjmenden

      I am creating a Help Ticketing system and I am following the SEAM documenation and making use of the EntityHome for CRUDing my Ticket Entity. The initial creation and updating works great, however when I go to view tickets, then click on a ticket which gets redirected back to my original ticket.xhtml page, with ticketId as a parameter, I can not for the life of me get the ticket to display.

      I need another pair of eyes to see where I am going wrong.


      ticket.xhtml

      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       xmlns:s="http://jboss.com/products/seam/taglib"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:h="http://java.sun.com/jsf/html"
       template="template.xhtml">
      
      <ui:define name="content">
      
       <h1 class="center">
       <h:outputText rendered="#{!ticketHome.managed}" value="Create Ticket"/>
       <h:outputText rendered="#{ticketHome.managed}" value="Edit Ticket"/>
       </h1>
      
       <h:messages globalOnly="true" styleClass="message"/>
      
       <h:form id="createTicket">
       <f:facet name="beforeInvalidField">
       <s:message/>
       </f:facet>
       <f:facet name="afterInvalidField">
       <h:graphicImage src="img/error.gif"/>
       </f:facet>
       <f:facet name="aroundInvalidField">
       <s:span styleClass="errors"/>
       </f:facet>
      
       <s:validateAll>
      
       <table class="form-center">
      
       <tr>
       <td colspan="2" align="center" class="table-heading">Contact Information</td>
       </tr>
       <tr>
       <td class="name">Name</td>
       <td align="right">
       <s:decorate>
       <h:inputText id="name" required="true" value="#{ticketHome.instance.name}"/>
       </s:decorate>
       </td>
       </tr>
       <tr>
       <td>
       <span class="name">Problem Description</span>
       </td>
       <td align="right">
       <s:decorate>
       <h:inputTextarea id="problemDescription" required="true" cols="50" rows="20" value="#{ticketHome.instance.problemDescription}"/>
       </s:decorate>
       </td>
       </tr>
      
       <tr>
       <td></td>
       <td align="right">
       <h:commandButton value="Create Ticket" action="#{ticketHome.persist}" rendered="#{!ticketHome.managed}"/>
       <h:commandButton value="Update Ticket" action="#{ticketHome.update}" rendered="#{ticketHome.managed}"/>
       <h:commandButton value="Delete Ticket" action="#{ticketHome.remove}" rendered="#{ticketHome.managed}"/>
       <s:link id="done" value="Done" linkStyle="button" propagation="end" view="/viewTickets.xhtml"/>
       </td>
       </tr>
      
       </table>
       </s:validateAll>
       </h:form>
      
      </ui:define>
      </ui:composition>
      




      Ticket.java
      @Entity
      @Name("ticket")
      @Role(name="tempTicket", scope=ScopeType.EVENT)
      @Table(name="tickets")
      public class Ticket implements Serializable {
      
       //seam-gen attributes (you should probably edit these)
       private int id;
       private Integer version;
       private String name;
      
      
       @Id @GeneratedValue
       public int getId() {
       return id;
       }
      
       public void setId(int id) {
       this.id = id;
       }
      
       @Version
       public Integer getVersion() {
       return version;
       }
      
       private void setVersion(Integer version) {
       this.version = version;
       }
      
       @NotNull
       @Column(length=50)
       @Length(max=50)
       public String getName() {
       return name;
       }
      
       @Lob
       public String getProblemDescription() {
       return problemDescription;
       }
      
       public void setProblemDescription(String problemDescription) {
       this.problemDescription = problemDescription;
       }
      
      }
      
      




      viewTickets.xhtml
      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:s="http://jboss.com/products/seam/taglib"
       xmlns:a="https://ajax4jsf.dev.java.net/ajax"
       template="template.xhtml">
      
       <!-- content -->
       <ui:define name="content">
       <div class="center">
       <h1>Tickets</h1>
       </div>
      
       <!-- Display the form for searching for tickets-->
       <s:validateAll>
       <table cellspacing="1" cellpadding="1" border="0" class="form-center">
       <tr>
       <td>
       Subject:
       </td>
       <td>
       <h:inputText value="#{tempTicket.subject}"/>
       </td>
       </tr>
      
       <tr>
       <td> </td>
       <td align="right">
       <h:commandButton value="Search" action="#{viewTickets.view}" styleClass="button" />
       </td>
       </tr>
       </table>
       </s:validateAll>
       <br />
       <br />
      
       <!-- ***************************************************************** -->
       <!-- Data Table of Tickets -->
       <!-- ***************************************************************** -->
       <h:dataTable value="#{tickets}"
       var="ticket"
       rendered="#{tickets.rowCount > 0}"
       styleClass="fiapps-table">
      
       <!-- Ticket Number -->
       <h:column>
       <f:facet name="header">
       <h:commandLink value="Ticket #" action="#{viewTickets.reorder}">
       <f:param name="orderBy" value="id"/>
       </h:commandLink>
       </f:facet>
       <s:link id="ticket" value="#{ticket.id}" view="/ticket.xhtml">
       <f:param name="ticketId" value="#{ticket.id}"/>
       </s:link>
       </h:column>
      
       <!-- Subject -->
       <h:column>
       <f:facet name="header">
       <h:commandLink value="Subject" action="#{viewTickets.reorder}">
       <f:param name="orderBy" value="subject"/>
       </h:commandLink>
       </f:facet>
       <h:outputText value="#{ticket.subject}" />
       </h:column>
      
       </h:dataTable>
       <br />
       <h:messages/>
       <br />
       <div class="center">
       <h:commandButton rendered="#{tickets.rowCount > 0}"
       type="submit"
       value="Refresh"
       action="#{viewTickets.findFirstPage}" />
       <h:commandButton action="#{viewTickets.findPreviousPage}"
       value="Previous Page"
       disabled="#{!viewTickets.previousPage}"
       rendered="#{tickets.rowCount > 0}"/>
       <h:commandButton action="#{viewTickets.findNextPage}"
       value="Next Page"
       disabled="#{!viewTickets.nextPage}"
       rendered="#{tickets.rowCount > 0}"/>
       </div>
       </h:form>
       <br />
       </ui:define>
      
      </ui:composition>
      
      




      when I click on the Ticket Number I get in the url bar: http://localhost:8080/fiapps/ticket.seam?ticketId=1&dataModelSelection=ticket%3Atickets%5B0%5D

      so I know the ticketId is getting passed. But the ticket is not getting loaded. Here are some additional classes.



      TicketHome.java
      @Name("ticketHome")
      public class TicketHome extends EntityHome<Ticket> {
      
      
       @Factory("ticket")
       public Ticket initPerson() {
       return getInstance();
       }
      
       protected Ticket createInstance() {
       Ticket ticket = new Ticket();
       return ticket;
       }
      
       public String getCreatedMessage() { return "New Ticket (#{ticket.subject}) created"; }
       public String getUpdatedMessage() { return "Ticket (#{ticket.subject}) updated"; }
       public String getDeletedMessage() { return "Ticket (#{ticket.subject}) deleted"; }
      }
      



      ViewTicketsBean.java - the relevant part
      @Name("viewTickets")
      @Stateful
      @Scope(ScopeType.CONVERSATION)
      public class ViewTicketsBean implements ViewTickets {
      
       @In(create=false, value="tempTicket") @Out(value="tempTicket")
       private Ticket tempTicket;
      
       @Logger
       private Log log;
      
       @DataModel
       private List<Ticket> tickets;
      
       @DataModelSelection
       private Ticket ticket;
      
       @In(create=true)
       private EntityManager entityManager;
      
      ...
      



      Any help would be greatly appreciated.

        • 1. Re: Using the EntityHome and problems therein
          kasim


          Just reading this real fast.

          Shouldnt it be "id"

          not "ticketId"?

          I dont see where you are telling the ticket that the name is "ticketId".

          • 2. Re: Using the EntityHome and problems therein
            kasim


            or rather tempTicket.Id?

            • 3. Re: Using the EntityHome and problems therein
              sjmenden

              I copied an example working project I created using seam gen where it generated:

              <s:link id="ticket" value="#{ticket.name}" view="/ticket.xhtml">
               <f:param name="ticketId" value="#{ticket.id}"/>
              </s:link>
              


              Whereas mine looks like this, the value doesn't matter since it is for display.
              <s:link id="ticket" value="#{ticket.id}" view="/ticket.xhtml">
               <f:param name="ticketId" value="#{ticket.id}"/>
              </s:link>
              


              tempTicket is only for the temporary Ticket instance for searching. In the dataTable I have tickets as my object and each individual is ticket, so ticket.id works.

              The problem is when I click the link above to try to view an individual ticket, no ticket gets loaded in the background.

              Honestly, it is because I don't understand the "magic" that is going on. ticketId is getting passed as a parameter, however, in the EntityHome and Home objects from Seam I can't see anywhere that it trys to read in the id or ticketId as a RequestParameter. I would really like to know how it magic is working when it works



              • 4. Re: Using the EntityHome and problems therein
                kasim


                Oh my bad.

                I didnt see the page was loading the DataModel.

                which example are you looking at btw?

                On my pages i just linked back to the page itself using s:link.

                • 5. Re: Using the EntityHome and problems therein
                  sjmenden

                  Self are blind......

                  I am still having problems I need to work out, but I got passed my initial problem, I wasn't adding the following to my TicketHome.java

                   @RequestParameter
                   Long ticketId;
                  
                   @Override
                   public Object getId()
                   {
                   if (ticketId==null)
                   {
                   return super.getId();
                   }
                   else
                   {
                   return ticketId;
                   }
                   }
                  
                   @Override @Begin
                   public void create() {
                   super.create();
                   }
                  


                  which explains where the RequestParameter definition is suppose to go.

                  • 6. Re: Using the EntityHome and problems therein
                    kasim


                    Just an FYI you could also post back to your original SLSB if you used just hte s:link, and have that data populated there, and then use that to forward onto your html page as well.