1 Reply Latest reply on May 8, 2007 12:25 PM by Chester Chee

    records in database table not display in dataTable

    Chester Chee Newbie


      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;
      public class AssetManagerAction implements AssetManager {
       private EntityManager em;
       @In(required=false, scope = SESSION)
       private User user;
       private String searchString;
       private int page;
       private List<Asset> assets;
       @In(required=false) @Out(required=false)
       private Asset selectedAsset;
       private List<AssetType> assetTypes;
       private Events events;
       private Log log;
       @In FacesMessages facesMessages;
       public void selectAsset(Asset selectedAsset)
       log.info("AssetManager.selectAsset() action called");
       this.selectedAsset = em.merge(selectedAsset);
       public void find()
       page = 0;
       public void nextPage()
       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}")
       .setFirstResult( page * getPageSize())
       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;
       @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;
       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"
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
      <ui:define name="body">
       <div class="section">
       <h:form id="assetSearchForm">
       <h:messages globalOnly="true" styleClass="message"/>
       <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:commandButton id="findAssets" value="Find Assets"
       action="#{assetManager.find}" reRender="searchResults"/>
       <h:outputLabel for="pageSize">Rows per page:</h:outputLabel>
       <h:inputText id="pageSize" value="#{assetManager.pageSize}" style="width: 50px"/>
       <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}">
       <f:facet name="header">Name</f:facet>
       <h:outputText value="#{_asset.name}"/>
       <f:facet name="header">Identifier</f:facet>
       <h:outputText value="#{_asset.identifier}"/>
       <f:facet name="header">Asset Type</f:facet>
       <h:outputText value="#{_asset.assetType.name}"/>
       <f:facet name="header">Started Date</f:facet>
       <h:outputText value="#{_asset.startedAt}"/>
       <f:facet name="header">Matured Date</f:facet>
       <h:outputText value="#{_asset.maturedAt}"/>
       <f:facet name="header">Action</f:facet>
       <s:link id="viewAsset" value="View Asset" action="#{assetManager.selectAsset(_asset)}"/>
       <s:link value="Next Page" action="#{assetManager.nextPage}" rendered="#{assetManager.nextPageAvailable}"/>

        • 1. Re: records in database table not display in dataTable
          Chester Chee Newbie

          And here is the log output when empty searchString is sent to the application.

          12:23:08,305 INFO [AssetManagerAction] AssetManagerAction.queryAssets() called
          12:23:08,716 INFO [STDOUT] Hibernate: select asset0_.id as id84_, asset0_.name as name84_, asset0_.identifier as identifier84_, asset0_.asset_type_id as asset6_84_, asset0_.started_at as started4_84_, asset0_.matured_at as matured5_84_ from asset asset0_ where lower(asset0_.name) like ? or lower(asset0_.identifier) like ? limit ?
          12:23:08,886 INFO [AssetManagerAction] AssetManagerAction.assets.size() = 3, pattern = %