I have a datatable and a commandbutton that calls hi().if i remove datatable commandbutton calls the method but with commandbutton and datatable the method is not called on button click.Where i m going wrong?
.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>
<link type="text/css" href="menu.css" rel="stylesheet" />
<style>
.p-panel-body {
height: 466px;
overflow: auto;
}
.ui-layout-north {
z-index: 20 !important;
overflow: visible !important;;
}
.ui-layout-north .ui-layout-unit-content {
overflow: visible !important;
}
</style>
</h:head>
<h:body >
<p:layout fullPage="true">
<p:layoutUnit position="north" size="50">
<ui:include src="mymenujsf.xhtml"></ui:include>
</p:layoutUnit>
<p:layoutUnit position="south" size="100" header="Bottom"
resizable="true" closable="true" collapsible="true">
<ui:include src="footer.xhtml"></ui:include>
</p:layoutUnit>
<p:layoutUnit position="west" size="150" header="Left"
resizable="true" closable="true" collapsible="true">
</p:layoutUnit>
<p:layoutUnit position="east" size="150" header="Right"
resizable="true" closable="true" collapsible="true" effect="drop">
<h:outputText value="Right unit content." />
</p:layoutUnit>
<p:layoutUnit position="center">
<p:panel id="paypanel" header="TDS Payment" closable="true"
toggleable="true" closeSpeed="500" toggleSpeed="1000">
<h:form method="POST" id="tds_payment" prependId="false">
<font size="2">
<fieldset>
<p:dataTable id="TdsPayment" var="tds" value="#{tdspaymentbean.listTdsPayment}" selection="#{tdspaymentbean.select}" rowKey="#{tds.id}">
<f:facet name="header">
Invoice Details
</f:facet>
<p:column selectionMode="multiple" >
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="id." />
</f:facet>
<h:outputText id="id" value="#{tds.id}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="InvoiceNo." />
</f:facet>
<h:outputText id="invoice_no" value="#{tds.invoice_no}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="InvoiceDate." />
</f:facet>
<h:outputText id="invoice_date" value="#{tds.payment_date}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Supplier." />
</f:facet>
<h:outputText id="supplier" value="#{tds.supplier}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Amount" />
</f:facet>
<h:outputText id="amount" value="#{tds.amount}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="TDSAmount" />
</f:facet>
<h:outputText id="tds_amt" value="#{tds.tds_Deducted_butnotpaid}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="TDSto be paid" />
</f:facet>
<p:selectBooleanCheckbox id="tds" value="#{tds.tds_select}" >
</p:selectBooleanCheckbox>
</p:column>
</p:dataTable>
</fieldset>
<p:inputText value="#{tdspaymentbean.tds_total}" id="total"></p:inputText>
<p:growl sticky="false" autoUpdate="true" id="message" life="10000"></p:growl>
<fieldset>
<p:commandButton value="Get" actionListener="#{tdspaymentbean.hi}"></p:commandButton>
</fieldset>
</font>
</h:form>
</p:panel>
</p:layoutUnit>
</p:layout>
</h:body>
</html>
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.faces.application.FacesMessage;
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.DataModel;
import javax.faces.model.SelectItem;
import javax.persistence.PersistenceContext;
import javax.sql.DataSource;
import sun.reflect.ReflectionFactory.GetReflectionFactoryAction;
import com.connection.AccessDbConnection;
import com.sun.org.apache.bcel.internal.generic.LSTORE;
@ManagedBean(name="tdspaymentbean")
@ViewScoped
public class Tds_Payment implements Serializable{
private transient DataSource ds;
private transient AccessDbConnection db;
private transient ResultSet rs;
private transient Connection con;
private transient Statement stmt;
private List<Tds_Payment> listTdsPayment=new ArrayList<Tds_Payment>();
private List<Tds_Payment> list=new ArrayList<Tds_Payment>();
private Tds_Payment dataItem;
private int id;
private String invoice_no;
private String supplier;
private String payment_date;
private double amount;
private double tds_amt;
private double tds_Deducted_butnotpaid;
private boolean tds_select;
private Tds_Payment select;
private double tds_total;
private double total,a=0;
int flag;
private DataModel selectableItems;
public Tds_Payment() {
super();
// TODO Auto-generated constructor stub
}
public Tds_Payment(String invoice_no, String supplier, String payment_date,
double amount, double tds_amt, double tds_Deducted_butnotpaid,
boolean tds_select, double tds_total) {
super();
this.invoice_no = invoice_no;
this.supplier = supplier;
this.payment_date = payment_date;
this.amount = amount;
this.tds_amt = tds_amt;
this.tds_Deducted_butnotpaid = tds_Deducted_butnotpaid;
this.tds_select = tds_select;
this.tds_total = tds_total;
}
public List<Tds_Payment> getList() {
return list;
}
public void setList(List<Tds_Payment> list) {
this.list = list;
}
public Tds_Payment getSelect() {
return select;
}
public void setSelect(Tds_Payment select) {
this.select = select;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getInvoice_no() {
return invoice_no;
}
public void setInvoice_no(String invoice_no) {
this.invoice_no = invoice_no;
}
public String getSupplier() {
return supplier;
}
public void setSupplier(String supplier) {
this.supplier = supplier;
}
public String getPayment_date() {
return payment_date;
}
public void setPayment_date(String payment_date) {
this.payment_date = payment_date;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
public double getTds_amt() {
return tds_amt;
}
public void setTds_amt(double tds_amt) {
this.tds_amt = tds_amt;
}
public double getTds_Deducted_butnotpaid() {
return tds_Deducted_butnotpaid;
}
public void setTds_Deducted_butnotpaid(double tds_Deducted_butnotpaid) {
this.tds_Deducted_butnotpaid = tds_Deducted_butnotpaid;
}
public boolean isTds_select() {
return tds_select;
}
public void setTds_select(boolean tds_select) {
this.tds_select = tds_select;
}
public double getTds_total() {
return tds_total;
}
public void setTds_total(double tds_total) {
this.tds_total = tds_total;
//cal();
}
public double getTotal() {
return total;
}
public void setTotal(double total) {
this.total = total;
}
public List<Tds_Payment> getListTdsPayment() {
try
{
con=new AccessDbConnection().getDBConnection("Invoice","root","root");
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from invoice.tds_deducted td,invoice.payment_details pd,invoice.purchase_invoice_header pih,invoice.payment_header ph where ph.payment_no=pd.payment_no and td.invoice_no=pih.invoice_no and td.invoice_no=pd.invoice_no";
rs=stmt.executeQuery(sql);
while(rs.next())
{
dataItem=new Tds_Payment();
dataItem.setId(rs.getInt("tempid"));
dataItem.setInvoice_no(rs.getString("invoice_no"));
dataItem.setPayment_date(rs.getString("payment_date"));
dataItem.setSupplier(rs.getString("supplier_name"));
dataItem.setAmount(rs.getDouble("grand_total"));
dataItem.setTds_Deducted_butnotpaid(rs.getDouble("tds_Deducted_butnotpaid"));
dataItem.setTds_select(isTds_select());
//dataItem.setTds_total(tds_total);
//System.out.println("@@@="+rs.getInt("tempid")+isTds_select());
listTdsPayment.add(dataItem);
}
}
catch(SQLException sqe)
{
sqe.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
return listTdsPayment;
}
public void setListTdsPayment(List<Tds_Payment> listTdsPayment) {
this.listTdsPayment = listTdsPayment;
}
public void cal(ActionEvent ae)
{
System.out.println("in cal");
List<Tds_Payment> items = (List<Tds_Payment>) selectableItems.getWrappedData();
List<Tds_Payment> listTdsPayment = new ArrayList<Tds_Payment>();
System.out.println("veda");
System.out.println("priyanka="+tds_select);
//System.out.println(listTdsPayment.add(dataItem));
System.out.println("gm="+tds_select);
for (Tds_Payment item : items) {
if (item.isTds_select()) {
listTdsPayment.add(item);
}
}
// do what you need to do with selected items
}
public String hi()
{
System.out.println("hi");
return null;
}
@Override
public String toString() {
return "Tds_Payment [tds_Deducted_butnotpaid="
+ tds_Deducted_butnotpaid + ", tds_total=" + tds_total + "]";
}
public void addMessage() {
System.out.println("in msg="+tds_select);
if(tds_select==true)
{
//cal();
}
else
{
addMessage();
}
}
public DataModel getSelectableItems() {
return selectableItems;
}
public void setSelectableItems(DataModel selectableItems) {
this.selectableItems = selectableItems;
}
}