iText Nested DataModels
clerum Jan 14, 2009 7:13 PMI'm trying to use itext to generate a PDF invoice. The layout is going to be something like this.
Account
--Site
----Line Items
I have the following page working.
<p:document xmlns:p="http://jboss.com/products/seam/pdf" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"> <p:font name="courier"> <f:facet name="header"> <p:font size="20"> <p:footer borderWidthTop="1" borderColorTop="green" borderWidthBottom="0" alignment="center">Clearfly Communications - <p:pageNumber /></p:footer> </p:font> </f:facet> <p:image value="/img/logo.gif" scalePercent="10" alignment="left" /> <p:table columns="2" widthPercentage="100"> <f:facet name="defaultCell"> <p:cell borderWidth="0" /> </f:facet> <p:cell><p:font style="bold"><p:paragraph>#{selinv.accountName}</p:paragraph></p:font></p:cell> <p:cell horizontalAlignment="right"><p:paragraph><p:text value="#{selinv.invoiceDate}"><f:convertDateTime type="both" pattern="MM/dd/yyyy"/></p:text></p:paragraph></p:cell> <p:cell><p:font style="bold"><p:paragraph>Account: #{selinv.accountCode} </p:paragraph></p:font></p:cell> <p:cell horizontalAlignment="right"><p:paragraph>Invoice: #{selinv.invoiceNumber}</p:paragraph></p:cell> </p:table> </p:font> <p:table columns="1" widthPercentage="100"> <ui:repeat value="#{siteList}" var="site"> <p:cell><p:font style="bold"><p:paragraph>#{site.sitename}</p:paragraph></p:font></p:cell> <p:table columns="2" widthPercentage="100"> <ui:repeat value="#{productList}" var="product"> <p:cell><p:paragraph>#{product.description}</p:paragraph></p:cell> <p:cell><p:paragraph>#{product.recAmount}</p:paragraph></p:cell> </ui:repeat> </p:table> </ui:repeat> </p:table> <p:newPage /> <p:barCode type="code128" code="A775-0243" barHeight="15" /> </p:document>
The issue is with the productList datamodel. It appears that it only gets called to be created once. Which makes because the productList variable is outjected so all my sites get the prodcuts for the first site listed. Is there another way to call the datamodel with parameters so that it gets recreated everytime the
<ui:repeat>
cycles?
import java.util.List; import javax.ejb.Remove; import javax.ejb.Stateful; import javax.persistence.EntityManager; import org.jboss.seam.annotations.Factory; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.datamodel.DataModel; @Stateful @Name("itemutil") public class ItemAction implements ItemUtil { @In EntityManager entityManager; @In(required=false) Site site; @DataModel List <MainTable> productList; @SuppressWarnings("unchecked") @Factory("productList") public void listProducts() { System.out.println("Selecting products for Account: " + site.getAccountcode() + " and Site: " + site.getId()); productList = (List<MainTable>) entityManager.createQuery("select maintable from MainTable maintable where accountcode=? and site_id=?") .setParameter(1, site.getAccountcode()) .setParameter(2, site.getId()) .getResultList(); } @Remove public void destroy() { } }