HI, Have used JSF h:data Table - the jsf datatable is coming empty, my sp is returning values hence getList returns values but only headers are seen in the browser, table values are not seen in the browser.
Following is my JSP
<h:panelGrid>
<f:facet name="header">
<h:outputText value="Employee Details" />
</f:facet>
<h:dataTable value="#{dataTableBean.list}" var="loc"
bgcolor="#F1F1F1" border="10" cellpadding="5" cellspacing="3"
first="0" rows="5" width="50%">
<h:column>
<f:facet name="header">
<h:outputText value="Sponsor ID" />
</f:facet>
<h:outputText value="#{loc.sponsorID}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Sponsor Name" />
</f:facet>
<h:outputText value="#{loc.sponsorName}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Distributor ID" />
</f:facet>
<h:outputText value="#{loc.distributorID}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Distributor Name" />
</f:facet>
<h:outputText value="#{loc.distributorName}" />
</h:column>
</h:dataTable>
</h:panelGrid>
</h:form>
MY Bean
public class DataTableBean {
private List<BillTransPay> list;
public List<BillTransPay> getList() {
String SP_BILLPAY = "{call sp_aw_BillTransPay(?,?,?,?,?,?,?)}";
Connection con = null;
ResultSet rs = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = java.sql.DriverManager
.getConnection(conString);
CallableStatement cbls = con
.prepareCall("{call sp_aw_BillTransPay(?,?,?,?,?,?,?)}");
cbls.setString(1, "csf");
cbls.setString(2, "20100101");
cbls.setString(3, "20100301");
cbls.setString(4, "B");
cbls.setString(5, "01CS");
cbls.setString(6, "ALL");
cbls.setInt(7, 14000);
rs = cbls.executeQuery();
list = new ArrayList<BillTransPay>();
while (rs.next()) {
BillTransPay btp = new BillTransPay();
btp.setSponsorID(rs.getString("SponsorCode"));
btp.setSponsorName(rs.getString("SponsorName"));
btp.setDistributorID(rs.getString("DistID"));
btp.setDistributorName(rs.getString("DistName"));
list.add(btp);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return list;
}
public void setList(List<BillTransPay> list) {
this.list = list;
}
}
Faces-Config.xml
**<managed-bean&开发者_高级运维gt;
<managed-bean-name>dataTableBean</managed-bean-name>
<managed-bean-class>
com.SQLProcess.dto.DataTableBean
</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>**
Just run a debugger or add a System.out.println(list);
right before return list;
to see if the method get called and the list really contains items.
Said that, this expensive DB job should really not be done in a getter. It can be called multiple times during a request. You don't want to unnecessarily hit/stress your DB. Move the DB job into the bean's constructor. Also, you're leaking DB resources by not explicitly closing the Connection
, Statement
and ResultSet
. You need to close them in finally
block of the same try
as where you have acquired them.
精彩评论