jeudi 12 mai 2016

save every checked row in datatable jsf

The value of selectBoolean checkbox is always false. Can anyone tell me whats the problem with my code.I want to filter the datatable list so that I can saved the checked row.

Here is the form

....//datatablecode                         
<p:column>
  <p:selectBooleanCheckbox value="#{transactionBean.flag_person}"/>
</p:column>                             
            </p:dataTable><br/>
        </p:column>
    </p:row>
</p:panelGrid>
 </p:panel>

<p:commandButton value="Save" process="@this" action="#{transactionBean.saveListStaf}" >
   <f:param name="id" value="#{transactionBean.id}" />
</p:commandButton>

Here is the method

public void saveListStaf(){

    try{        
        MysqlConn conn = new MysqlConn();
        con = conn.getConnection();

        System.out.println("checked staff list=" +getFlag_peserta()); //when i checked the value always false

        TransactionOfStaf item = null;

        for (int i = 0; i < listStaf.size(); i++) { 

            item = new TransactionOfStaf ();
            item = listStaf.get(i);

            if(item.getId() == 0){
                if(item.getFlag_person()==true){

                    String sql = "INSERT INTO "+ dbname_m_transaction +" (id, no_staf, name, action_by, action_on) VALUES(?,?,?,?,?)";
                    pst = con.prepareStatement(sql); 

                    pst.setInt(1, this.getId());
                    pst.setString(2, item.getNo_staf());
                    pst.setString(3, item.getName());
                    pst.setString(4, (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("no_staf"));
                    pst.setString(5, dateFormat.format(date));      

                    pst.executeUpdate();
                }

Here is class of item

private boolean flag_person;

public boolean getFlag_person() {
    return flag_person;
}

public void setFlag_person(boolean flag_person) {
    this.flag_person= flag_person;
}




Aucun commentaire:

Enregistrer un commentaire