Problem while updating data.

UI Components for JSF
Post Reply
priyanka
Posts: 48
Joined: 15 Feb 2012, 11:59

27 Mar 2012, 11:45

Hello sir i am facing problem while updating the data...
I am able to retrieve data from database on selection of value from first and second selectonemenu..
It retrieves the cheque no from database but now i m not able to update it..
Here is my code..
.xhtml

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns:p="http://primefaces.org/ui"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets">
	<h:head></h:head>
	<h:body>
		<h:form method="POST" id="payment" prependId="false">
			<table>
								<tr>
									<td><b><h:outputText value="Payment No:"></h:outputText>
									</b>&nbsp;&nbsp;&nbsp;&nbsp;</td>
									<td><p:selectOneMenu id="payment_no" effect="fold"
											value="#{aaaabean.payment_no}" required="true"
											editable="true">
											<f:selectItem itemLabel="Select One" itemValue=""></f:selectItem>
											<f:selectItems id="paymentselect" for="payment_no"
												itemLabel="#{aaaabean.lstPayment_Names}"
												itemValue="#{aaaabean.lstPayment_Names}"
												value="#{aaaabean.lstPayment_Names}">
											</f:selectItems>
											<f:ajax render=" invoice_no" for="payment_no" />
												
											

										</p:selectOneMenu> <p:tooltip for="payment_no" value="Enter Payment No."
											showEffect="slide" hideEffect="explode"></p:tooltip></td>
									</tr>
									<tr>
										<td><b><h:outputText value="Invoice:"></h:outputText>
													</b>&nbsp;&nbsp;&nbsp;&nbsp;</td>
													<td><p:selectOneMenu editable="true" id="invoice_no"
															label="Invoice" value="#{aaaabean.invoice_no}">
															<f:selectItem itemLabel="Select One" itemValue=""></f:selectItem>
															<f:selectItems id="invoice_lst" for="invoice_no"
																itemLabel="#{aaaabean.lstInvoice_No}"
																itemValue="#{aaaabean.lstInvoice_No}"
																value="#{aaaabean.lstInvoice_No}"></f:selectItems>
														<f:ajax render="cheque_no " listener="#{aaaabean.retrieveInvoiceDetails}"></f:ajax>
														</p:selectOneMenu> <p:tooltip for="invoice_no" value="select invoice"
															showEffect="slide" hideEffect="explode"></p:tooltip></td>
									</tr>
									<tr>
									<td><b><h:outputText value="Supplier:"></h:outputText>
									</b>&nbsp;&nbsp;&nbsp;&nbsp;</td>
									<td>
									<p:selectOneMenu id="supplier" effect="fold"
											value="#{aaaabean.supplier}" required="true"
											editable="true" for="payment_no"
											>
											<f:selectItem itemLabel="Select One" itemValue=""></f:selectItem>
											<f:selectItems id="supplier_nameselect" for="supplier"
												itemLabel="#{aaaabean.lstSupplier}"
												value="#{aaaabean.lstSupplier}"
												itemValue="#{aaaabean.lstSupplier}"></f:selectItems>
											<f:ajax render=" invoice_no" for="supplier"></f:ajax>
										</p:selectOneMenu> <p:tooltip for="supplier" value="Enter supplier"
											showEffect="slide" hideEffect="explode"></p:tooltip>
									</td>
									</tr>
									
												
												
												<tr>
													<td><b><h:outputText value="Cheque No:"></h:outputText>
													</b>&nbsp;&nbsp;&nbsp;&nbsp;</td>
													<td><p:inputText id="cheque_no" label="Cheque No."
															style="width:60%"
															
															value="#{aaaabean.cheque_no}">

														</p:inputText> <p:tooltip for="cheque_no" value="Enter Cheque No."
															showEffect="slide" hideEffect="explode"></p:tooltip></td>
												</tr>
												
								</table>
								
								<p:commandButton id="edit" value="Edit" 	action="#{aaaabean.edit}" 	 immediate="true" update="edit payment_no"></p:commandButton>
								<p:commandButton id="update" value="Update" actionListener="#{aaaabean.updateEntry}" 
										></p:commandButton>
		</h:form>
	</h:body>
</html>
.java

Code: Select all

package com.finance;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.IllegalFormatException;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import javax.persistence.PersistenceContext;
import javax.sql.DataSource;
import org.primefaces.component.datatable.DataTable;
import org.primefaces.event.SelectEvent;
import com.connection.AccessDbConnection;
@ManagedBean(name="aaaabean")
@ViewScoped

public class Aaaa implements Serializable{

	private transient DataSource ds;
    private transient AccessDbConnection db;
    private transient ResultSet rs,rs1;
    private transient Connection con;
    private transient Statement stmt;
    private String payment_no;
    private String supplier;
    private String invoice_no;
    private List<SelectItem> lstSupplier;
    private List<SelectItem> lstInvoice_No;
    private List<SelectItem> lstPayment_Names;
    int flag=0,newFlag=0;
    int paymentNoFlag=0;
    private String cheque_no;
    private boolean editDisabled=false;
    private String id;
    
    
    
    public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getCheque_no() {
		return cheque_no;
	}

	public void setCheque_no(String cheque_no) {
		this.cheque_no = cheque_no;
	}

	public boolean isEditDisabled() {
    	   
		return editDisabled;
	}

	public void setEditDisabled(boolean editDisabled) {
		this.editDisabled = editDisabled;
	}
	public String getPayment_no() {
		return payment_no;
	}
	public void setPayment_no(String payment_no) {
		this.payment_no = payment_no;
	}
	public String getSupplier() {
		return supplier;
	}
	public void setSupplier(String supplier) {
		this.supplier = supplier;
	}
	public String getInvoice_no() {
		return invoice_no;
	}
	public void setInvoice_no(String invoice_no) {
		this.invoice_no = invoice_no;
	}
	public List<SelectItem> getLstSupplier() {
		lstSupplier = new ArrayList<SelectItem>();
        SelectItem test = new SelectItem();
        
        	try
        	{
        		con=new AccessDbConnection().getDBConnection("Invoice","root","root");
    			stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE); 
    			String sql="select distinct (supplier) from purchase_invoice_header where balance_amount<>'0'";
    			//String sql="select distinct(pih.supplier) from purchase_invoice_header pih,payment_details pd where pd. balance_amount<>0;";
    			rs=stmt.executeQuery(sql);
    			while(rs.next())
                {
                test = new SelectItem();
                test.setLabel(rs.getString("supplier")== null ? "" : rs.getString("supplier"));
                test.setValue(rs.getString("supplier")== null ? "" : rs.getString("supplier"));
                lstSupplier.add(test);
                }
    			
    			rs.close();
           	}

        	catch (SQLException ex)
        	{
        		ex.printStackTrace();
        	}
        	catch (Exception ex)
        	{
        		ex.printStackTrace();
        	}
        
		return lstSupplier;
	}
	public void setLstSupplier(List<SelectItem> lstSupplier) {
		this.lstSupplier = lstSupplier;
	}
	public List<SelectItem> getLstInvoice_No() {
		lstInvoice_No = new ArrayList<SelectItem>();
        SelectItem test = new SelectItem();
        if(newFlag==1)
        {
        		try
	        	{
	        		con=new AccessDbConnection().getDBConnection("Invoice","root","root");
	    			stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
	    			System.out.println(this.id);
	    			String sql1="select pih.invoice_no,pd.id from purchase_invoice_header pih,payment_details pd where pih.balance_amount<>'0' and pih.balance_amount>'0' and pd.invoice_no=pih.invoice_no and pd.payment_no='"+this.payment_no+"'" ;
	    			rs=stmt.executeQuery(sql1);

	    			while(rs.next())
	                {
	                test = new SelectItem();
	                test.setLabel(rs.getString("invoice_no")== null ? "" : rs.getString("invoice_no")+"-"+rs.getInt("id"));
	                test.setValue(rs.getString("invoice_no")== null ? "" : rs.getString("invoice_no")+"-"+rs.getInt("id"));
	                lstInvoice_No.add(test);
	                }
	    			System.out.println("@#@#@"+lstInvoice_No);
	    		//	rs.close();
	           	}

	        	catch (SQLException ex)
	        	{
	        		ex.printStackTrace();
	        	}
	        	catch (Exception ex)
	        	{
	        		ex.printStackTrace();
	        	}
        }
        if(newFlag==0)
        {
        	try
        	{
        		con=new AccessDbConnection().getDBConnection("Invoice","root","root");
    			stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    			
    			String sql="select invoice_no from purchase_invoice_header where supplier='"+this.supplier+"' and balance_amount<>'0' and balance_amount>'0'" ;
    			rs=stmt.executeQuery(sql);

    			while(rs.next())
                {
                test = new SelectItem();
                test.setLabel(rs.getString("invoice_no")== null ? "" : rs.getString("invoice_no"));
                test.setValue(rs.getString("invoice_no")== null ? "" : rs.getString("invoice_no"));
                lstInvoice_No.add(test);
                }
    			
    			rs.close();
           	}

        	catch (SQLException ex)
        	{
        		ex.printStackTrace();
        	}
        	catch (Exception ex)
        	{
        		ex.printStackTrace();
        	}
        }
		return lstInvoice_No;
	}
	public void setLstInvoice_No(List<SelectItem> lstInvoice_No) {
		this.lstInvoice_No = lstInvoice_No;
	}
	public List<SelectItem> getLstPayment_Names() {
		lstPayment_Names = new ArrayList<SelectItem>();
        SelectItem test = new SelectItem();
        if(paymentNoFlag==1)
        {
        	try
        	{
        		con=new AccessDbConnection().getDBConnection("Invoice","root","root");
    			stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    			
    			String sql="select payment_no from payment_header" ;
    			rs=stmt.executeQuery(sql);

    			while(rs.next())
                {
                test = new SelectItem();
                test.setLabel(rs.getString("payment_no")== null ? "" : rs.getString("payment_no"));
                test.setValue(rs.getString("payment_no")== null ? "" : rs.getString("payment_no"));
                lstPayment_Names.add(test);
                }
    			
    			rs.close();
           	}

        	catch (SQLException ex)
        	{
        		ex.printStackTrace();
        	}
        	catch (Exception ex)
        	{
        		ex.printStackTrace();
        	}
        }
		return lstPayment_Names;
	}
	public void setLstPayment_Names(List<SelectItem> lstPayment_Names) {
		this.lstPayment_Names = lstPayment_Names;
	}
    
	public String edit()
	{
		paymentNoFlag=1;
		editDisabled=true;
		newFlag=1;
		flag=1;
		return null;
	}
	
	public String updateEntry(ActionEvent ae)
	{
		
		try{System.out.println("Before");
		con=new AccessDbConnection().getDBConnection("Invoice","root","root");
		System.out.println("after");
		System.out.println("insisde save");
		
		stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE); 
		getPayment_no();
		getInvoice_no();
		getSupplier();
		getCheque_no();
		setInvoice_no(invoice_no);
		setSupplier(supplier);
		setPayment_no(payment_no);
		setCheque_no(cheque_no);
		rs=stmt.executeQuery("select * from payment_details where payment_no='"+payment_no+"'");
		
		if(rs!=null)
		{
			payment_no=getPayment_no();
			invoice_no=getInvoice_no();
			
			supplier=getSupplier();
			cheque_no=getCheque_no();
		String sql="update payment_details set cheque_no='"+this.cheque_no+"' where payment_no='"+this.payment_no+"' and id='"+this.id+"' and invoice_no='"+this.invoice_no+"'";
		int i=stmt.executeUpdate(sql); 
		System.out.println("i="+i);
		
		System.out.println("After xecute");
		System.out.println("Record updated Successfuly");
		FacesContext context=FacesContext.getCurrentInstance();
		context.addMessage(null, new FacesMessage("Record Updated Successfully"));
		}
			
		}
		catch(SQLException se)
		{
			se.printStackTrace();
		}
		catch(ClassNotFoundException cnfe)
		{
			cnfe.printStackTrace();
		}
		catch(IllegalFormatException ife)
		{
			ife.printStackTrace();
		}
		catch(Exception se)
		{
			se.printStackTrace();
		}
	
		return null;
	}
	
	public String retrieveInvoiceDetails()
	{
		try{
			con=new AccessDbConnection().getDBConnection("Invoice","root","root");
			stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
			//System.out.println("SSSSSSSS"+this.id);
			//String sql1="select pd.id from payment_header pd,purchase_invoice_header pih where pd.invoice_no=pih.invoice_no and pd.invoice_no='"+this.invoice_no+"'";
			//stmt.executeQuery(sql1);
			if(invoice_no!=null)
			{
				int start=invoice_no.indexOf("-")+1;
				System.out.println(start);
				int end=invoice_no.length();
				System.out.println(end);
				System.out.println(end-start);
				char buf[]=new char[end-start];
				System.out.println(buf);
				invoice_no.getChars(start,end, buf,0);
				this.id=new String(buf);
				System.out.println(this.id);
			}
			System.out.println(this.payment_no);
			String sql="select * from purchase_invoice_header pih,payment_details pd where pih.balance_amount<>'0' and pih.balance_amount>'0' and pd.invoice_no=pih.invoice_no and pd.payment_no='"+this.payment_no+"' and pd.id='"+this.id+"'" ;
			rs=stmt.executeQuery(sql);
			while(rs.next())
			{
				
				cheque_no=rs.getString("cheque_no");
				System.out.println(cheque_no);
		    	
			}
				
		}
		catch(SQLException se)
		{
			se.printStackTrace();
		}
		catch(ClassNotFoundException cnfe)
		{
			cnfe.printStackTrace();
		}
		catch(IllegalFormatException ife)
		{
			ife.printStackTrace();
		}
		catch(Exception se)
		{
			se.printStackTrace();
		}
		finally
		{
			//db.closeConnection(con);
			//db.closeStatement(stmt);
		}
		return invoice_no;
	}
}

Primefaces version:3.1.RC1
JSf2.0
primefaces-extensions
IDE Eclipse Helios
Apache TomCat 6

priyanka
Posts: 48
Joined: 15 Feb 2012, 11:59

28 Mar 2012, 07:33

I am not getting where i m going wrong????????
Primefaces version:3.1.RC1
JSf2.0
primefaces-extensions
IDE Eclipse Helios
Apache TomCat 6

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests