1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
package Test;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlDataTable;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.model.DataModel;
import javax.faces.model.SelectItem;
import org.richfaces.model.impl.ListDataModel;
import Test.BDD;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.sql.Connection;
public class Recherche {
private String MO;
private DataModel list = new ListDataModel();
//private ArrayList<EMPLOYES> list;
private ResultSet RS;
public String getMO() {
return MO;
}
public void setMO(String MO) {
this.MO = MO;
}
@SuppressWarnings("unchecked")
public DataModel getlist() {
if (list == null) {
Connection con = new BDD().getCon();
try {
//list = new ArrayList<EMPLOYES>();
String SqlStr = " select CODE_SOC, MATRI, NOM, PRENOM, FONCTION as LIBEL,'EXTERNE' as TYPE from DC_DEMANDEUREX ";//WHERE UPPER(DC_DEMANDEUREX.NOM) LIKE '%"+ MO.toUpperCase() +"%' OR UPPER(DC_DEMANDEUREX.PRENOM) LIKE '%"+ MO.toUpperCase() +"%'UNION" ;
// SqlStr =SqlStr+ " select CODE_SOC, MATRI, NOM, PRENOM, LIBEL,'INTERNE' as INTERNE from DC_EMPLOYES WHERE UPPER(DC_EMPLOYES.NOM) LIKE '%"+ MO.toUpperCase() +"%'OR UPPER(DC_EMPLOYES.PRENOM) LIKE '%"+ MO.toUpperCase() +"%' ORDER BY TYPE DESC, CODE_SOC, MATRI, NOM, PRENOM ";
Statement stmt= con.createStatement();
RS = stmt.executeQuery(SqlStr);
while(RS.next())
{
list.setWrappedData( new EMPLOYES(RS.getString("CODE_SOC"),RS.getInt("MATRI"),RS.getString("NOM"),RS.getString("PRENOM"),RS.getString("LIBEL"),RS.getString("TYPE") ));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return list;
}
public void selectionneElement(ActionEvent evt) {
// On récupère la datatable.
HtmlDataTable table = getParentDatatable((UIComponent) evt.getSource());
// On récupère l'objet affiché à la bonne ligne de la datatable.
Object o = table.getRowData();
// On récupère aussi son index
int index = table.getRowIndex();
// Suite du traitement sur l'objet sélectionné.
}
private HtmlDataTable getParentDatatable(UIComponent compo) {
if (compo == null) {
return null;
}
if (compo instanceof HtmlDataTable) {
return (HtmlDataTable) compo;
}
return getParentDatatable(compo.getParent());
}
} |
Partager