Dear All
I am new to JSF, i built a Client list page on which i gave an industry list and tried to give a client list on the basis of selected industry but unable to do.. i am pasting the Code which consists of 1. Industry List Managed Bean 2. Client List Managed Bean and 3. Clients.xhtml
please suggest...
Clients.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html 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"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head xmlns:h="#unknown">
<style type="text/css" media="screen,projection">
@import url(style/multiplecolumns.css);
</style>
<style type="text/css" media="screen,projection">
@import url(style/formcentering.css);
</style>
</h:head>
<div id="container1">
<ui:include src="headerwhite.xhtml" xmlns:ui="#unknown" />
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<h:form id="form" xmlns:h="#unknown">
<div id="block_center">
<p:datatable var="act" value="#{MCD.act}" xmlns:p="#unknown">
rows="12" paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="9,12,15"
>
<p:column style="width:10%;font-family:fantasy">
<f:facet name="header" xmlns:f="#unknown">Logo</f:facet>
<p:graphicimage value="images/homepage/#{act.logofilename}.jpg" />
</p:column>
<p:column style="width:50%;text-align: left;font-family:fantasy">
<f:facet name="header" xmlns:f="#unknown">Title</f:facet>
<hutputtext value="#{act.title}" style="font-family:cursive" />
</p:column>
</p:datatable>
</div>
<div id="block_left">
<p:datatable var="act" value="#{IL.act}" xmlns:p="#unknown">
<p:column style="width:100%;text-align: left;font-family:fantasy">
<f:facet name="header" xmlns:f="#unknown">Industry:</f:facet>
<h:commandlink action="#{MCD.CreateList}" value="#{act.industry}" style="font-family:cursive">
<f:setpropertyactionlistener target="#{MCD.selectedIndustry}" value="NewValue" xmlns:f="#unknown" />
</h:commandlink>
</p:column>
</p:datatable>
</div>
<div id="block_right">
</div>
</h:form>
</body>
<ui:include src="footer.xhtml" xmlns:ui="#unknown" />
</div>
</html>
package Database.Settings;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;
@ManagedBean (name="MCD")
@SessionScoped
public final class ManipulateClientData {
dbConnectionSQLServer dbc = new dbConnectionSQLServer( true );
Connection CN;
PreparedStatement SQL;
ResultSet RS;
private List<clients> act = new ArrayList<clients>();
private String ID;
private String Title;
private String add1;
private String tel;
private String mobile;
private String email;
private String msg;
private String logofilename;
private String industry;
private String selectedIndustry;
public ManipulateClientData() {
CreateList ();
}
public void CreateList() {
ID = "";
Title = "";
add1 = "";
tel = "";
mobile = "";
email = "";
logofilename="";
industry="";
try {
System.out.println( "Line No. 1: " );
CN = dbc.getCN();
System.out.println( "Line No. 2: " );
SQL = CN.prepareStatement("SELECT C.ID, C.Title+'" + selectedIndustry + "' Title, CA.add1, CA.Tel, CA.mobile, CA.email, " +
"CA.Add3 logofilename, I.Title industry FROM Coa321 CA " +
" Left Join UL_Coa C On C.ID=CA.ID " +
" Left Join Industries I On CA.Industry_ID=I.ID " +
" Where I.Title = '" + selectedIndustry + "'" +
"ORDER BY C.Title");
System.out.println( "Starting Fetching: " + selectedIndustry);
RS = SQL.executeQuery();
System.out.println( "Loop Start: " );
while ( RS.next() ) {
act.add(new Clients(RS.getString("ID"), RS.getString("Title"), RS.getString("Add1"), RS.getString("tel"), RS.getString("mobile"), RS.getString("email"), RS.getString("logofilename"), RS.getString("industry")));
}
RS.close();
System.out.println( "Loop End: " );
} catch (Exception e) {
System.out.println( "Ooops its an error! " + e.toString() );
}
}
public Connection getCN() {
return CN;
}
public void setCN(Connection CN) {
this.CN = CN;
}
public String getID() {
return ID;
}
public void setID(String ID) {
this.ID = ID;
}
public String getTitle() {
return Title;
}
public void setTitle(String Title) {
this.Title = Title;
}
public List<clients> getAct() {
return act;
}
public void setAct(List<clients> act) {
this.act = act;
}
public String getAdd1() {
return add1;
}
public void setAdd1(String add1) {
this.add1 = add1;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getLogofilename() {
return logofilename;
}
public void setLogofilename(String logofilename) {
this.logofilename = logofilename;
}
public String getIndustry() {
return industry;
}
public void setIndustry(String industry) {
this.industry = industry;
}
public String getSelectedIndustry() {
return selectedIndustry;
}
public void setSelectedIndustry(String selectedIndustry) {
this.selectedIndustry = selectedIndustry;
}
}
package Database.Settings;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;
@ManagedBean (name="IL")
@SessionScoped
public class IndustryList {
dbConnectionSQLServer dbc = new dbConnectionSQLServer( true );
Connection CN;
PreparedStatement SQL;
ResultSet RS;
private List<clients> act = new ArrayList<clients>();
private String industry;
private String selectedIndustry;
public IndustryList() {
industry="";
try {
System.out.println( "IL: Line No. 1: " );
CN = dbc.getCN();
System.out.println( "IL: Line No. 2: " );
SQL = CN.prepareStatement("SELECT Distinct I.Title industry FROM Coa321 CA " +
" Left Join UL_Coa C On C.ID=CA.ID " +
" Left Join Industries I On CA.Industry_ID=I.ID");
System.out.println( "IL: Starting Fetching: " );
RS = SQL.executeQuery();
System.out.println( "IL: Loop Start: " );
while ( RS.next() ) {
System.out.println("IL: " + RS.getRow() );
act.add(new Clients("", "", "", "", "", "", "", RS.getString("industry")));
}
RS.close();
System.out.println( "IL: Loop End: " );
} catch (Exception e) {
System.out.println( "Ooops its an error! " + e.toString() );
}
}
public Connection getCN() {
return CN;
}
public void setCN(Connection CN) {
this.CN = CN;
}
public List<clients> getAct() {
return act;
}
public void setAct(List<clients> act) {
this.act = act;
}
public String getIndustry() {
return industry;
}
public void setIndustry(String industry) {
this.industry = industry;
}
public String getSelectedIndustry() {
return selectedIndustry;
}
public void setSelectedIndustry(String selectedIndustry) {
this.selectedIndustry = selectedIndustry;
}
}</clients></clients></clients></clients></clients></clients></clients></clients>