aspose file tools*
The moose likes JSF and the fly likes Filtering a list on selection from a value from another list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Filtering a list on selection from a value from another list" Watch "Filtering a list on selection from a value from another list" New topic
Author

Filtering a list on selection from a value from another list

Nasir Abbas
Greenhorn

Joined: Mar 09, 2012
Posts: 1
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

<?xml version='1.0' encoding='UTF-8' ?>
<!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>
<style type="text/css" media="screen,projection">
/* backslash hack hides from IEmac \*/
@import url(style/multiplecolumns.css);
/* end hack */
</style>
<style type="text/css" media="screen,projection">
/* backslash hack hides from IEmac \*/
@import url(style/formcentering.css);
/* end hack */
</style>
</h:head>
<div id="container1">
<ui:include src="headerwhite.xhtml" />
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<h:form id="form">
<div id="block_center">
<p:dataTable var="act" value="#{MCD.act}"
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">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">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}">
<p:column style="width:100%;text-align: left;font-family:fantasy">
<f:facet name="header">Industry:</f:facet>
<h:commandLink action="#{MCD.CreateList}" value="#{act.industry}" style="font-family:cursive" >
<f:setPropertyActionListener target="#{MCD.selectedIndustry}" value="NewValue"/>
</h:commandLink>
</p:column>
</p:dataTable>
</div>
<div id="block_right">
</div>
</h:form>
</body>
<ui:include src="footer.xhtml" />
</div>
</html>



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

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;

/**
*
* @author Administrator
*/
@ManagedBean (name="MCD")
@SessionScoped
public final class ManipulateClientData {
/** Creates a new instance of 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;
}
}



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

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;
/**
*
* @author Administrator
*/
@ManagedBean (name="IL")
@SessionScoped
public class IndustryList {
/** Creates a new instance of ManipulateClientData */
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;
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Filtering a list on selection from a value from another list