[jboss-user] [JBoss Seam] - @DataModel to dataTable problem/question

mpw do-not-reply at jboss.com
Thu Aug 2 21:29:47 EDT 2007


Hello all:

 i need some help with an error rendering my DataModel
to the JSF datatable component

the page takes textinput "card_id" passes it to the Action method
for a query that joins 2 tables and ouputs the results into
a List. the problem is that the Page does not resolve my
@DataModel List  books variable in the DataTable.

any help would be appreciated.

Michael

 (using seam 2.0 with jboss as 4.2)


     the server error is:

An Error Occurred:
/borrower.xhtml: For input string: "isbn"
+- Stack Trace

javax.el.ELException: /borrower.xhtml: For input string: "isbn"
	at com.sun.facelets.compiler.TextInstruction.write(TextInstruction.java:50)
	at com.sun.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:39)
	at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:269)
	at com.sun.faces.renderkit.html_basic.TableRenderer.encodeChildren(TableRenderer.java:307)
	at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:809)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
	at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
	at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:809)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
	at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:577)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
	at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)


my JSF page is:

<!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"
				template="template.xhtml">

<!-- content -->
<ui:define name="content">
<ui:include src="conversations.xhtml" />

<h:form>
	<h1>Search Borrower</h1>
        <h:outputText value="(e.g., Enter Borrowers card_id number )"/>
	 
		<h:inputText id="card_id" value="#{borrower.card_id}" style="width: 165px;" /> 
		<h:commandButton value="Find Borrowers Books" action="#{borrowerList.queryBorrower}" styleClass="button" /> 
        <h:commandButton value="Clear Results" action="#{borrowerList.clear}" styleClass="button" /> 
	
	
    <h:outputLabel for="pageSize">Maximum results to display:</h:outputLabel>  

    <h:selectOneMenu value="#{borrowerList.pageSize}" id="pageSize">
        <f:selectItem itemLabel="1" itemValue="1"/>
        <f:selectItem itemLabel="5" itemValue="5"/>
    	<f:selectItem itemLabel="10" itemValue="10"/>
    	<f:selectItem itemLabel="20" itemValue="20"/>
    </h:selectOneMenu>


    
</h:form>



<h:form>
  <h:outputText value="No Borrower found with that card_id" rendered="#{books != null and books.rowCount==0}"/>
	<h:dataTable id="checkedoutbooks" var="_b" value="#{books}"  rendered="#{books.rowCount>0}">
		<h:column>
			<f:facet name="header">ISBN</f:facet>
			#{_b.isbn}
		</h:column>
		<h:column>
			<f:facet name="header">Title</f:facet>
			#{_b.title}
		</h:column>
		<h:column>
			<f:facet name="header">Author</f:facet>
			 #{_b.author}
		</h:column> 
         
                <h:column>
			<f:facet name="header">Checkout Date</f:facet>
			 #{_b.checkoutdate}
		</h:column>

                <h:column>
			<f:facet name="header">Due Date</f:facet>
			 #{_b.duedate}
		</h:column>

		<h:column>
			<f:facet name="header">PageCnt</f:facet>
			#{_b.page_cnt}
		</h:column>
                <h:column>
			<f:facet name="header">Minutes</f:facet>
			#{_b.minutes}
		</h:column>
	</h:dataTable>    
</h:form>



	<h1>Current Books</h1>


</ui:define>

<!-- sidebar -->
<ui:define name="sidebar">

<h1>MPW components</h1>
 End of Page - MPW  

</ui:define>

</ui:composition>



and my action class is:


  @Stateless
  @Scope(ScopeType.SESSION)
  @Name("borrowerList")
  @Restrict("#{identity.loggedIn}")
  public class BorrowerAction implements BorrowerListInterface, Serializable {

   @PersistenceContext
   private EntityManager em;   

   @DataModel
   private List books;

      @Out(required=false)
    private Books book;


      @In(create=true)
   private Borrower borrower;
   
   @Logger
   private Log log;

   private int pageSize = 10;
      private int page = 0;


      @Factory("books")
  public void  queryBorrower() { 
  
        String str = "select book.isbn, book.title, book.author, " +
                     "book.page_cnt, book.minutes, book.checkoutdate, book.duedate " +
                     "from Books book join book.borrowers b " +
                     " where b.card_id = :card_id   order by book.title asc ";

        log.info("Querying books table for all borrowers with card_id = " + borrower.getCard_id());
        books  = em.createQuery(str)
	    .setParameter("card_id", borrower.getCard_id())
            .setMaxResults(pageSize)
            .getResultList();

       ListIterator pairs = books.listIterator();

       while(pairs.hasNext()) {
            Object[] pair    = (Object[]) pairs.next();


            log.info( " MPW " +     " **isbn**     "  + pair[0] +
                          " **title**    "  + pair[1]  +
                          " **author**   "  + pair[2]  +
                          " **page_cnt** "  + pair[3]  +
                          " **minutes**  "  + pair[4]);


       }

  }

   public boolean isNextPageAvailable() {
      return books!=null && books.size()==pageSize;
   }

   
    public void nextPage() {
      page++;
      queryBorrower();
   }

   public int getPageSize() {
      return pageSize;
   }

   public void setPageSize(int pageSize) {
      this.pageSize = pageSize;
   }

   public String clear() {
      books = null;
      book  = null;
      return "main";
   }


      /*
   @Destroy @Remove
   public void destroy() {}
      */

  }
    





View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4070360#4070360

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4070360



More information about the jboss-user mailing list