records in database table not display in dataTable
cchee May 8, 2007 12:15 PMHi,
First of all, I apologize if this question has already been asked before. I have been struggling to get the simply search list to work with my current project using Seam with Ajax4JSF. I pretty much follow the example in HotelBooking to implement my search function. I have dumped a lot of output at different breakpoint in the code and traced all the way to the .xhtml page. It seems, the dataTable is not displaying the actual rows even though I was able to get the number of records from the database. The column headers rendered probably, but just no data being displayed below. I am not sure what i did wrong and greatly appreciated any enlightenment.
My Search code are the followings:-
package action; import static javax.persistence.PersistenceContextType.EXTENDED; import static org.jboss.seam.ScopeType.EVENT; import static org.jboss.seam.ScopeType.SESSION; import java.util.List; import javax.ejb.Remove; import javax.ejb.Stateful; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.jboss.seam.annotations.Begin; import org.jboss.seam.annotations.Destroy; import org.jboss.seam.annotations.End; import org.jboss.seam.annotations.Factory; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Out; import org.jboss.seam.annotations.Scope; import org.jboss.seam.annotations.datamodel.DataModel; import org.jboss.seam.annotations.security.Restrict; import org.jboss.seam.log.Log; import org.jboss.seam.core.Events; import org.jboss.seam.core.FacesMessages; import model.Asset; import model.AssetType; import model.User; @Stateful @Name("assetManager") @Scope(SESSION) @Restrict public class AssetManagerAction implements AssetManager { @PersistenceContext(type=EXTENDED) private EntityManager em; @In(required=false, scope = SESSION) private User user; private String searchString; private int page; @DataModel private List<Asset> assets; //@DataModelSelection @In(required=false) @Out(required=false) private Asset selectedAsset; @In(required=false) @Out(required=false) private List<AssetType> assetTypes; @In private Events events; @Logger private Log log; @In FacesMessages facesMessages; @Begin public void selectAsset(Asset selectedAsset) { log.info("AssetManager.selectAsset() action called"); this.selectedAsset = em.merge(selectedAsset); } public void find() { page = 0; queryAssets(); } public void nextPage() { page++; queryAssets(); } @SuppressWarnings("unchecked") private void queryAssets() { log.info("AssetManagerAction.queryAssets() called"); assets = em.createQuery("select a from Asset a where lower(a.name) like #{pattern} or lower(a.identifier) like #{pattern}") .setMaxResults(getPageSize()) .setFirstResult( page * getPageSize()) .getResultList(); log.info("AssetManagerAction.assets.size() = " + assets.size() + ", pattern = #{pattern}"); } public boolean isNextPageAvailable() { return assets != null && assets.size() == getPageSize(); } public int getPageSize() { return user.getRowsPerPage(); } public void setPageSize(int pageSize) { if (pageSize < 5) { pageSize = 5; } user.setRowsPerPage(pageSize); } @Factory(value="pattern", scope=EVENT) public String getSearchPattern() { return searchString==null ? "%" : '%' + searchString.toLowerCase().replace('*', '%') + '%'; } public String getSearchString() { return searchString; } public void setSearchString(String searchString) { this.searchString = searchString; } @End public void cancel() {} @Destroy @Remove public void destroy() {} }
and my xhtml file is the following:-
<!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: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" xmlns:rich="http://richfaces.ajax4jsf.org/rich" xmlns:a="https://ajax4jsf.dev.java.net/ajax" template="layout/template.xhtml"> <ui:define name="body"> <div class="section"> <h:form id="assetSearchForm"> <h:messages globalOnly="true" styleClass="message"/> <rich:panel> <f:facet name="header">Search Asset</f:facet> <h:inputText id="searchString" value="#{assetManager.searchString}" style="width: 165px"> <a:support event="onkeyup" actionListener="#{assetManager.find}" reRender="searchResults"/> </h:inputText> <h:commandButton id="findAssets" value="Find Assets" action="#{assetManager.find}" reRender="searchResults"/> <br/> <h:outputLabel for="pageSize">Rows per page:</h:outputLabel> <h:inputText id="pageSize" value="#{assetManager.pageSize}" style="width: 50px"/> </rich:panel> </h:form> </div> <a:outputPanel id="searchResults"> <div class="section"> <h:outputText value="No Assets Found" rendered="#{assets != null and assets.rowCount == 0}"/> <h:outputText value="Total number of records: #{assets.rowCount}"/> <h:dataTable id="assets" values="#{assets}" var="_asset" rendered="#{assets.rowCount gt 0}"> <h:column> <f:facet name="header">Name</f:facet> <h:outputText value="#{_asset.name}"/> </h:column> <h:column> <f:facet name="header">Identifier</f:facet> <h:outputText value="#{_asset.identifier}"/> </h:column> <h:column> <f:facet name="header">Asset Type</f:facet> <h:outputText value="#{_asset.assetType.name}"/> </h:column> <h:column> <f:facet name="header">Started Date</f:facet> <h:outputText value="#{_asset.startedAt}"/> </h:column> <h:column> <f:facet name="header">Matured Date</f:facet> <h:outputText value="#{_asset.maturedAt}"/> </h:column> <h:column> <f:facet name="header">Action</f:facet> <s:link id="viewAsset" value="View Asset" action="#{assetManager.selectAsset(_asset)}"/> </h:column> </h:dataTable> <s:link value="Next Page" action="#{assetManager.nextPage}" rendered="#{assetManager.nextPageAvailable}"/> </div> </a:outputPanel> </ui:define> </ui:composition>