0 Replies Latest reply on Nov 9, 2011 1:27 PM by Andres Pardo

    combobox RichFaces problem

    Andres Pardo Newbie

      need to load a combobox RichFaces with the result of another combobox, but the event does not work to charge the other with the result of the first combo.

       

      <rich:comboBox id="origen" value="${combo.idOrigen}" directInputSuggestions="true" defaultLabel="Seleccione origen" width="219">

                                        <f:selectItems value="#{combo.origen}" />

                                 <a4j:support event="onchange" reRender="destino" />

                           </rich:comboBox><br></br>

                          

                           <rich:comboBox id="destino" value="${combo.idDestino}" directInputSuggestions="true" defaultLabel="Seleccione destino" width="219">

                              <f:selectItems value="#{combo.destino}"/>                                                       

                           </rich:comboBox>

       

      package prueba;

       

       

      import java.sql.CallableStatement;

      import java.sql.Connection;

      import java.sql.ResultSet;

      import java.sql.SQLException;

      import java.util.ArrayList;

      import java.util.List;

       

       

      import javax.faces.bean.ManagedBean;

       

       

      import javax.faces.model.SelectItem;

       

       

      import oracle.jdbc.internal.OracleTypes;

      import dao.ConexionBDOracle;

       

       

      @ManagedBean(name="combo")

      public class TextBean {

       

       

                private String idOrigen;

                private String idDestino;

                private ArrayList<SelectItem> origen  = new ArrayList<SelectItem>();

                private ArrayList<SelectItem> destino = new ArrayList<SelectItem>();

       

       

       

       

                public List<SelectItem> getOrigen() {

                          Connection conexion             = null;

                          CallableStatement procedimiento = null;

                          ResultSet rs                    = null;

       

                          try{

                                    conexion = ConexionBDOracle.GetConecction();

                                    procedimiento = conexion.prepareCall("{ ?= call PASAJES.SP_BUSCA_ORIGEN_DESTINO(?,?) }");

                                    procedimiento.registerOutParameter(1,OracleTypes.CURSOR);

                                    procedimiento.setString(2, "");

                                    procedimiento.setString(3, "1");

                                    procedimiento.execute();

                                    rs = (ResultSet) procedimiento.getObject(1);

       

                                    while(rs.next()){

                                              origen.add(new SelectItem(rs.getString(2), rs.getString(1)));

                                    }

       

                                    procedimiento.close();

                                    rs.close();

                                    conexion.close();

                          }catch(Exception ex){

                                    ex.printStackTrace();

                          }

                          return origen;

                }

       

       

                public List<SelectItem> getDestino() {

              System.out.println("idciudad: "+idOrigen);

                          Connection conexion = null;

                          CallableStatement procedimiento = null;

                          ResultSet rs = null;

       

                          try {

                                    conexion = ConexionBDOracle.GetConecction();

                                    procedimiento = conexion

                                                        .prepareCall("{ ?= call PASAJES.SP_BUSCA_ORIGEN_DESTINO(?,?) }");

                                    procedimiento.registerOutParameter(1, OracleTypes.CURSOR);

                                    procedimiento.setString(2, idOrigen);

                                    procedimiento.setString(3, "2");

                                    procedimiento.execute();

                                    rs = (ResultSet) procedimiento.getObject(1);

       

       

                                    while (rs.next()) {

                                              destino.add(new SelectItem(rs.getString(2), rs.getString(1)));

                                    }

                                    rs.close();

                                    procedimiento.close();

                                    conexion.close();

                          } catch (Exception e) {

                                    // TODO Logear error

                                    e.printStackTrace();

                          } finally {

                                    try{

                                              if(conexion != null && !conexion.isClosed()){

                                                        if(rs != null)

                                                                  rs.close();

                                                        if(procedimiento != null)

                                                                  procedimiento.close();

                                                        conexion.close();

                                              }

                                    }catch(SQLException ex){

                                              try {

                                                        conexion.close();

                                              } catch (Exception e) {

                                                        ex.printStackTrace();

                                              }

                                              // TODO Logear error de SQL

                                              ex.printStackTrace();

                                    }

                          }

       

       

                          return destino;

                }

       

       

                public String getIdOrigen() {

                          return idOrigen;

                }

       

       

                public void setIdOrigen(String idOrigen) {

                          this.idOrigen = idOrigen;

                }

       

                public String getIdDestino() {

                          return idDestino;

                }

       

       

                public void setIdDestino(String idDestino) {

                          this.idDestino = idDestino;

                }

       

                public void setOrigen(ArrayList<SelectItem> origen) {

                          this.origen = origen;

                }

       

                public void setDestino(ArrayList<SelectItem> destino) {

                          this.destino = destino;

                }

      }