2 Replies Latest reply on Oct 9, 2008 4:08 PM by Germiyan Ogul

    problem when try to reach the properties from a pdf page

    Germiyan Ogul Newbie
      I try to make a xhtml page which will be rendered as pdf file. when I try to get a value it returns the default value of that property not the value of that instance.

      here is my code
      <p:paragraph>ShowList #{invoiceHome.showList}!</p:paragraph>
      it is supposed to return 1 but it returns 0 instead.

      How can I reach the value of that instance?
        • 2. Re: problem when try to reach the properties from a pdf page
          Germiyan Ogul Newbie

          <!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.org/rich"
                          xmlns:a4j="http://richfaces.org/a4j"
                          xmlns:p="http://jboss.com/products/seam/pdf">
          
          
          <p:document> 
             
              <p:font size="24">
                  <p:paragraph spacingAfter="50"></p:paragraph>
              </p:font>
             
                    
                      <p:paragraph>ShowList #{invoiceHome.showList}</p:paragraph>
                      <p:paragraph>
             <p:text value="#{invoiceHome.instance.invoiceNumber}">
              
              </p:text>
          </p:paragraph>
                      
                      
                    <p:document xmlns:p="http://jboss.com/products/seam/pdf"   
                      xmlns:ui="http://java.sun.com/jsf/facelets"
                      title="Hello">   
             
             <p:table columns="3" headerRows="1">
                <p:cell>name</p:cell>
                <p:cell>owner</p:cell>
                <p:cell>size</p:cell>
                <ui:repeat value="#{invoiceHome.ii}" var="doc">
                   <p:cell>#{doc.amounts}</p:cell>
                   <p:cell>#{doc.totalprice}</p:cell>
                   <p:cell>#{doc.singleprice}</p:cell>
                </ui:repeat>
             </p:table>
          </p:document>            
          
                    
                    
          <p:paragraph>
             <p:text value="#{invoiceHome.instance.invoiceNumber}">
              
              </p:text>
          </p:paragraph>
          
          
          
              <p:paragraph alignment="justify">
                  
              </p:paragraph>
          </p:document>
          
          
          </ui:composition>





          package tr.com.setur.dfs.entity.order;
          
          import java.io.Serializable;
          import java.math.BigDecimal;
          import java.util.ArrayList;
          import java.util.Date;
          import java.util.List;
          
          import javax.persistence.Entity;
          import javax.persistence.Id;
          import javax.persistence.GeneratedValue;
          import javax.persistence.OneToMany;
          import javax.persistence.Transient;
          import javax.persistence.Version;
          import org.hibernate.validator.Length;
          import org.jboss.seam.annotations.In;
          import org.jboss.seam.annotations.Out;
          import org.jboss.seam.annotations.Unwrap;
          
          import tr.com.setur.dfs.entity.product.Product;
          import tr.com.setur.dfs.entity.product.ProductCard;
          import tr.com.setur.dfs.entity.sales.Currency;
          import tr.com.setur.dfs.entity.sales.Item;
          
          @Entity
          public class Invoice implements Serializable {
               
                
               private Long id;
               private Integer version;
               
               
               
               @In @Out
               private String invoiceNumber;
               @In @Out
               private String orderNumber,firmName,firmCode,currencyName,status,productName;
               @In @Out
               private Date orderDate,invoiceDate;
               @In @Out
               private Integer amounts;
               
               @In @Out
               private BigDecimal price,totalPrice;     
               
               @In @Out
               private List<InvoiceItem> itemInvoice;
               
               
               private OrderForm orderform1,orderform2;
               
                    
               @Id @GeneratedValue
               public Long getId() {
                    return id;
               }
          
               public void setId(Long id) {
                    this.id = id;
               }
               
               @Version
               public Integer getVersion() {
                    return version;
               }
          
               private void setVersion(Integer version) {
                    this.version = version;
               }
               
               public Date getInvoiceDate() {
                    if (invoiceDate==null){
                         invoiceDate=new Date();
                    }
                    return invoiceDate;
               }
          
               public void setInvoiceDate(Date invoiceDate) {
                    this.invoiceDate = invoiceDate;
               }
          
               
               @OneToMany
               public List<InvoiceItem> getItemInvoice() {
                    if(itemInvoice==null)
                    {
                    itemInvoice= new ArrayList<InvoiceItem>();          
                    }
                    return itemInvoice;
               }
          
               public void setItemInvoice(List<InvoiceItem> itemInvoice) {
                    this.itemInvoice = itemInvoice;
               }
               
                    
               public OrderForm getOrderform1() {
                    return orderform1;
               }
          
               public void setOrderform1(OrderForm orderform1) {
                    this.orderform1 = orderform1;
               }
          
               public OrderForm getOrderform2() {
                    return orderform2;
               }
          
               public void setOrderform2(OrderForm orderform2) {
                    this.orderform2 = orderform2;
               }
          
               public String getInvoiceNumber() {
                    return invoiceNumber;
               }
          
               public void setInvoiceNumber(String invoiceNumber) {
                    this.invoiceNumber = invoiceNumber;
               }
          
               public String getOrderNumber() {
                    return orderNumber;
               }
          
               public void setOrderNumber(String orderNumber) {
                    this.orderNumber = orderNumber;
               }
          
               public String getFirmName() {
                    return firmName;
               }
          
               public void setFirmName(String firmName) {
                    this.firmName = firmName;
               }
          
               public String getFirmCode() {
                    return firmCode;
               }
          
               public void setFirmCode(String firmCode) {
                    this.firmCode = firmCode;
               }
          
               public String getCurrencyName() {
                    return currencyName;
               }
          
               public void setCurrencyName(String currencyName) {
                    this.currencyName = currencyName;
               }
          
               public String getStatus() {
                    return status;
               }
          
               public void setStatus(String status) {
                    this.status = status;
               }
          
               public String getProductName() {
                    return productName;
               }
          
               public void setProductName(String productName) {
                    this.productName = productName;
               }
          
               public Date getOrderDate() {
                    return orderDate;
               }
          
               public void setOrderDate(Date orderDate) {
                    this.orderDate = orderDate;
               }
          
               public Integer getAmounts() {
                    return amounts;
               }
          
               public void setAmounts(Integer amounts) {
                    this.amounts = amounts;
               }
          
               public BigDecimal getPrice() {
                    return price;
               }
          
               public void setPrice(BigDecimal price) {
                    this.price = price;
               }
          
               public BigDecimal getTotalPrice() {
                    return totalPrice;
               }
          
               public void setTotalPrice(BigDecimal totalPrice) {
                    this.totalPrice = totalPrice;
               }
               
               
          }




          package tr.com.setur.dfs.session.order;
          
          import java.io.File;
          import java.math.BigDecimal;
          import java.text.DateFormat;
          import java.text.SimpleDateFormat;
          import java.util.Date;
          import java.util.List;
          import java.util.Locale;
          
          import javax.persistence.Query;
          
          
          import org.hibernate.SessionFactory;
          import org.hibernate.Session;
          
          import org.hibernate.Transaction;
          import org.hibernate.cfg.Configuration;
          import org.jboss.seam.ScopeType;
          import org.jboss.seam.annotations.Factory;
          import org.jboss.seam.annotations.In;
          import org.jboss.seam.annotations.Name;
          import org.jboss.seam.annotations.Begin;
          import org.jboss.seam.annotations.Out;
          import org.jboss.seam.annotations.Scope;
          import org.jboss.seam.annotations.Unwrap;
          import org.jboss.seam.annotations.web.RequestParameter;
          import org.jboss.seam.framework.EntityHome;
          
          
          import tr.com.setur.dfs.entity.order.Invoice;
          import tr.com.setur.dfs.entity.order.InvoiceItem;
          import tr.com.setur.dfs.entity.order.InvoiceRecord;
          import tr.com.setur.dfs.entity.order.OrderForm;
          import tr.com.setur.dfs.entity.order.OrderItem;
          import tr.com.setur.dfs.entity.order.PlanItem;
          import tr.com.setur.dfs.entity.order.PriceItem;
          import tr.com.setur.dfs.entity.product.Brand;
          import tr.com.setur.dfs.entity.product.ProductCard;
          import org.hibernate.cfg.AnnotationConfiguration; 
          
          
          @Name("invoiceHome")
          
          public class InvoiceHome extends EntityHome<Invoice>
          {
               
              @RequestParameter 
              Long invoiceId;
              
              private InvoiceItem ii=new InvoiceItem();
              private List<OrderItem> pc;
              
              private PlanItem planitem;
              private BigDecimal sum=new BigDecimal(0);
              private String orderNumber; 
            
              private int showList=0;
             
            
             
             
          
              
                @Override
              public Object getId() 
              { 
                  if (invoiceId==null)
                  {
                      return super.getId();
                  }
                  else
                  {
                      return invoiceId;
                  }
              }
               @Override @Begin
              public void create() {
                  super.create();
              }
              
               public InvoiceItem getItemInvoice(){
                    
                    for (InvoiceItem oi : this.instance.getItemInvoice()) {
                            
                         this.instance.setOrderNumber(oi.getOrderform().getOrderNumber());
                                this.instance.setAmounts(Integer.parseInt(oi.getOrderitem().getAmounts()));
                                this.instance.setCurrencyName(oi.getOrderitem().getPriceItem().getCurrency().getName());
                                this.instance.setFirmCode(oi.getOrderform().getFirma().getCode());
                                this.instance.setFirmName(oi.getOrderform().getFirma().getName());
                                this.instance.setProductName(oi.getOrderitem().getPriceItem().getProduct().getProductCard().getName());
                                this.instance.setOrderDate(oi.getOrderform().getOrderDate());
                               this.instance.setStatus(oi.getOrderform().getStatus());
                                this.instance.setPrice(oi.getSingleprice());
                                ii.setAmounts(Integer.parseInt(oi.getOrderitem().getAmounts()));
                                ii.setSingleprice(oi.getSingleprice());
                                ii.setTotalprice(oi.getTotalprice());
                            }
                    
                    return ii;
                    
                    
               }
               
             
               
              public void getProduct(){
                  
                   orderNumber=this.instance.getOrderform1().getOrderNumber();
                   System.out.println("Order Name");
                   System.out.println(orderNumber);
                   
                   OrderForm order= (OrderForm) this.getEntityManager().createQuery("select p from OrderForm p where p.orderNumber=:orderNumber").setParameter("orderNumber", orderNumber).getSingleResult();
                   this.ii.setOrderform(order);
                   pc=this.ii.getOrderform().getItem();
              
                   
                   for (OrderItem oi : pc) {
                   System.out.println("Burdayim");     
                   System.out.println(oi.getAmounts());     
                   this.ii.setProduct(oi.getPriceItem());
                   this.ii.setOrderitem(oi);
                   this.ii.setAmounts(Integer.parseInt(this.ii.getOrderitem().getAmounts()));
                   BigDecimal m=new BigDecimal(this.ii.getOrderitem().getAmounts());
            /*       if(this.ii.getOrderitem().getPriceItem().getPrice()==null){
                        this.ii.getOrderitem().getPriceItem().setPrice(new BigDecimal(0));
                   }*/
                   this.ii.setSingleprice(this.ii.getOrderitem().getPriceItem().getPrice());
                   this.ii.setTotalprice(this.ii.getSingleprice().multiply(m));
                   }
                   
                   getItemInvoice();
                   
                   
              //     OrderItem orderitem=(OrderItem) this.getEntityManager().createQuery("select p from OrderItem p ").setParameter("orderName", orderName).getSingleResult();
                   
                   
          /*          PriceItem product=(PriceItem) this.getEntityManager().createQuery("select p from PriceItem p where p. ");
                    this.ii.setProduct(product);*/
                   
              }
             
              public void findProduct(){
                   
            //       pc=this.getEntityManager().createQuery("select p from Invoice p where p.ordername=:ordername").setParameter("ordername",this.instance.getOrderform2().getName()).getResultList();
                   
              }
              
              public void selectProduct(){
              
              showList=1;
                   
              String sel="select p from OrderForm p join p.item pb where p.id=:invoiceId";
              OrderForm order= (OrderForm) this.getEntityManager().createQuery(sel).setParameter("invoiceId",invoiceId).getSingleResult();
              this.ii.setOrderform(order);
               pc=this.ii.getOrderform().getItem();
              
               for(OrderItem oi: pc){
                    this.ii.setProduct(oi.getPriceItem());
                   this.ii.setOrderitem(oi);
                   this.ii.setAmounts(Integer.parseInt(this.ii.getOrderitem().getAmounts()));
                   BigDecimal m=new BigDecimal(this.ii.getOrderitem().getAmounts());
                   if(this.ii.getOrderitem().getPriceItem().getPrice()==null){
                        this.ii.getOrderitem().getPriceItem().setPrice(new BigDecimal(0));
                   }
                   this.ii.setSingleprice(this.ii.getOrderitem().getPriceItem().getPrice());
                   this.ii.setTotalprice(this.ii.getSingleprice().multiply(m));
                   this.instance.setAmounts(Integer.parseInt(ii.getOrderitem().getAmounts()));
                   this.instance.setCurrencyName(ii.getOrderitem().getPriceItem().getCurrency().getName());
                   this.instance.setProductName(ii.getOrderitem().getPriceItem().getProduct().getProductCard().getName());
                   this.instance.setPrice(ii.getSingleprice());
              }
              
               
               this.instance.setOrderNumber(ii.getOrderform().getOrderNumber());
               this.instance.setFirmCode(ii.getOrderform().getFirma().getCode());
               this.instance.setFirmName(ii.getOrderform().getFirma().getName());
               this.instance.setOrderDate(ii.getOrderform().getOrderDate());
               this.instance.setStatus(ii.getOrderform().getStatus());
          
               
                
              }
              
              public String addItem(){
              
                   this.instance.getItemInvoice().add(ii);
                   sum=ii.getTotalprice().add(sum);
                   getItemInvoice();
                   
                   
              //     copyProduct();
                   
                   ii=new InvoiceItem();
              
                         return "ok";
               }
              
              public void deleteProduct(){
              
              pc.remove(invoiceId);
              /*String del2="delete from Invoice where id=:invoiceId";
                  Query q=this.getEntityManager().createQuery(del2);
                  q.setParameter("invoiceId",invoiceId);
                 q.executeUpdate();*/
              }
            
              
              public void copyProduct(){
                   try {
                        showList=0;
                        sum=null;
                        int counter=0;
                        for (InvoiceItem oi : this.instance.getItemInvoice()) {
                             counter++;
                             System.out.println("Burdayim");     
                            System.out.println(oi.getAmounts());     
                            
                            Invoice i = new Invoice();
                       
                            i.setOrderNumber(oi.getOrderform().getOrderNumber());
                                 i.setAmounts(Integer.parseInt(oi.getOrderitem().getAmounts()));
                                 i.setInvoiceNumber(this.instance.getInvoiceNumber());
                                 i.setCurrencyName(oi.getOrderitem().getPriceItem().getCurrency().getName());
                                 i.setFirmCode(oi.getOrderform().getFirma().getCode());
                                 i.setFirmName(oi.getOrderform().getFirma().getName());
                                 i.setProductName(oi.getOrderitem().getPriceItem().getProduct().getProductCard().getName());
                                 i.setOrderDate(oi.getOrderform().getOrderDate());
                                i.setStatus(oi.getOrderform().getStatus());
                                 i.setPrice(oi.getSingleprice());
                                 i.setInvoiceDate(this.instance.getInvoiceDate());
                                 
                                 this.getEntityManager().persist(i);
                             getEntityManager().flush();
                            
                            
                            
                            }
                        System.out.println("counter");
                       System.out.println(counter);
                       
             /*          Invoice num=new Invoice();
                       num.setInvoiceNumber(this.instance.getInvoiceNumber());
                       this.getEntityManager().persist(num);
                       getEntityManager().flush();*/
                        
                       this.instance.setItemInvoice(null);
                         this.instance.setInvoiceNumber(null);
                         this.setPc(null);
                                 
                         /* File f = new File("C:\\Projects\\dfs\\hibernate.cfg.xml"); 
                                AnnotationConfiguration ac=new AnnotationConfiguration();
                            
                            SessionFactory sessionFactory = ac.configure(f).buildSessionFactory();
                            Session session = sessionFactory.openSession();
                                Transaction tx = session.beginTransaction();
                            session.save(i);
                            tx.commit();
                            session.close();
                          */
          
                                      
                                      
                                 } catch(Exception e) {
                                      e.printStackTrace();
                                 }
              }
              
             
              
              public void createNumber(){
                   
                   BigDecimal date=new BigDecimal(this.instance.getInvoiceDate().getYear());
                   BigDecimal year=new BigDecimal(1900);
                   BigDecimal Y=date.add(year);
                   StringBuffer st=new StringBuffer(Y.toString());
                   st.append("-");
                   Long i=new Long(1);
                   try{
                   i=(Long)this.getEntityManager().createQuery("select count(distinct p.invoiceNumber) from Invoice p").getSingleResult();
                   i++;
                   }catch(Exception e){
                        System.out.println(e.toString());
                   }finally{
                   if(i==null){
                   i= new Long(1);
                   }
                   st.append(i);
                   }
                   
                   
                   this.instance.setInvoiceNumber(st.toString());
                   
                   this.instance.setItemInvoice(null);
                  }
              
          
               public InvoiceItem getIi() {
                    if (ii == null) {
                         ii = new InvoiceItem();
                    }
                    return ii;
               }
          
               public void setIi(InvoiceItem ii) {
                    this.ii = ii;
               }
          
               public List<OrderItem> getPc() {
                    return pc;
               }
          
               public void setPc(List<OrderItem> pc) {
                    this.pc = pc;
               }
          
               
               public PlanItem getPlanitem() {
                    return planitem;
               }
               public void setPlanitem(PlanItem planitem) {
                    this.planitem = planitem;
               }
          
               public BigDecimal getSum() {
                    return sum;
               }
               public void setSum(BigDecimal sum) {
                    this.sum = sum;
               }
          
               public int getShowList() {
                    return showList;
               }
               public void setShowList(int showList) {
                    this.showList = showList;
               }
               
               
               
          
              
              
                
          }