JSF - Pass conditioned checkbox value for Update statement

1

I have the following problem, I have a datatable in Primefaces that shows me a series of records, to which I can edit them. At the time of editing, it sends me a Modal window that shows me the editable fields between them, a checkbox that is preloaded according to the condition of the DB field.

<p:outputLabel value="Contenedor Temperado?" />
<h:selectBooleanCheckbox id="tempcheckbox" value="#{ordenRetiroBean.ord.es_temperado!=0}"> 
</h:selectBooleanCheckbox>

Now, this value, when updating, sends me to my method in the Bean the list of affected fields and also the active session (audit).

 public void commitEdit() throws SQLException {
    daoOrdenRetiro.editOrdenRetiro(ord, sessionUsuario);
    listadoOrdenes = daoOrdenRetiro.findAll();
}

And my DAO method what I have is the following way, that if or.getest_orden == 1, make this sentence, otherwise do the other.

public void editOrdenRetiro(OrdenRetiro or,Usuario u) throws SQLException {
    conexion con = new conexion();
    PreparedStatement pst;
    con.getConnection().setAutoCommit(false);
    ResultSet rs = null;
    String query = "";
    try {
        if (or.getEs_temperado()==1) {
            query = "update publico.ordenretiro"
                    + "set cia_codigo=?, ids_itinerario=?, lin_codigo=?, booking=?, pto_codigo=?, mov_xcuenta=?, cant_tipocont=?, "
                    + "tipo_carga=?, req_especial=?,"
                    + "inv_seguridad=?, temperatura=?, ventilacion=?, observaciones=?, loc_salida=?, loc_entrada=?, "
                    + "fecha_mod=current_timestamp, usu_mod=?"
                    + "where cod_ordenretiro=?";
        } else {
            query = "update publico.ordenretiro"
                    + "set cia_codigo=?, ids_itinerario=?, lin_codigo=?, booking=?, pto_codigo=?, mov_xcuenta=?, cant_tipocont=?, "
                    + "tipo_carga=?, req_especial=?, "
                    + "inv_seguridad=?, observaciones=?, loc_salida=?, loc_entrada=?, fecha_mod=current_timestamp, usu_mod=?"
                    + "where cod_ordenretiro=?";
        }
        pst = con.getConnection().prepareStatement(query);
        if (or.getEs_temperado() == 1) {
            pst.setString(1, or.getCia_codigo());
            pst.setInt(2, or.getIds_itinerario());
            pst.setString(3, or.getLin_codigo());
            pst.setString(4, or.getBooking());
            pst.setString(5, or.getPto_codigo());
            pst.setString(6, or.getMov_xcuenta());
            pst.setString(7, or.getCant_tipocont());
            pst.setString(8, or.getTipo_carga());
            pst.setString(9, or.getReq_especial());
            pst.setString(10, or.getInv_seguridad());
            pst.setString(12, or.getTemperatura());
            pst.setString(13, or.getVentilacion());
            pst.setString(14, or.getObservaciones());
            pst.setInt(15, or.getLoc_salida());
            pst.setInt(16, or.getLoc_entrada());
            pst.setString(17, u.getLogin());
            pst.executeUpdate();
        }
        if (or.getEs_temperado() == 0) {
            pst.setString(1, or.getCia_codigo());
            pst.setInt(2, or.getIds_itinerario());
            pst.setString(3, or.getLin_codigo());
            pst.setString(4, or.getBooking());
            pst.setString(5, or.getPto_codigo());
            pst.setString(6, or.getMov_xcuenta());
            pst.setString(7, or.getCant_tipocont());
            pst.setString(8, or.getTipo_carga());
            pst.setString(9, or.getReq_especial());
            pst.setString(10, or.getInv_seguridad());
            pst.setString(11, or.getObservaciones());
            pst.setInt(12, or.getLoc_salida());
            pst.setInt(13, or.getLoc_entrada());
            pst.setString(14, u.getLogin());
            pst.executeUpdate();
        }

        con.getConnection().commit();
    } catch (Exception e) {
        System.out.println("DAO EDITAR ORDEN RETIRO: " + e.getMessage());
        con.getConnection().rollback();
    } finally {
        con.desconectar();
    }
}

But send me the error

  

value="# {ordenRetiroBean.ord.es_temperado! = 0}": Illegal Situation for Operation of Putting Value

    
asked by Jorge 01.02.2017 в 17:29
source

1 answer

1

I already did it. What I did was create a boolean in my Bean.

boolean temperado2;

Which, I give value in the method that is executed when I press Edit, which opens a modal window.

public void showEditDialog(OrdenRetiro orde) {
    ord = orde;
    temperado2 = (ord.getEs_temperado() != 0);
}

And in my xhtml what I do is give it the value of the boolean:

<p:outputLabel value="Contenedor Temperado?" />
     <h:selectBooleanCheckbox id="tempcheckbox" value="#{ordenRetiroBean.temperado2}"> 
</h:selectBooleanCheckbox>
    
answered by 01.02.2017 в 20:42