I have 2 <h:selectOneMenu>
components and one of them depends of the selection of the other. When you select one value of the first menu component, then the second changes with the event of onchange="submit()"
and valueChangeListener="#{Usuario.cmbDatos_action}"
of the first menu:
<h:selectOneMenu id="cmbCombo" binding="#{Usuario.cmbDatos}" value="#{Usuario.id}"
onchange="submit()" valueChangeListener="#{Usuario.cmbDatos_action}">
<f:selectItems value="#{beanCombos.datos}"></f:selectItems>
</h:selectOneMenu>
It is like Countries and Cities of the selected Country. The first menu is loaded as follows:
@ManagedBean
@RequestScoped
public class BeanCombos {
private List<SelectItem> Datos;
public BeanCombos() {
try {
clsConexion objConexion = new clsConexion();
String strSQL = "SELECT * FROM Usuarios";
objConexion.ResultSetSQL = objConexion.EjecutarConsulta(strSQL);
Datos = new ArrayList<SelectItem>();
while (objConexion.ResultSetSQL.next()) {
Usuario objUsuario = new Usuario();
objUsuario.setId(String.valueOf(objConexion.ResultSetSQL.getInt("Codigo")));
objUsuario.setNombre(objConexion.ResultSetSQL.getString("Nombres").toUpperCase());
Datos.add(new SelectItem(objUsuario.getId(), objUsuario.getNombre()));
}
} catch(Exception ex) {
String strError = ex.getMessage().toString();
}
}
public List<SelectItem> getDatos() {
return Datos;
}
}
But when I select one value of the first menu I don't know how load the next menu. I've tried it as follows:
public String cmbDatos_action() {
try {
int intValor = Integer.parseInt(cmbDatos.getValue().toString());
} catch(Exception ex) {
}
return null;
}
In what part of method cmbDatos_action()
can I put the code to load the second menu?