Using the EntityHome and problems therein
sjmenden Nov 16, 2006 3:21 PMI 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.