I have 2 <h:selectOneMenu>components, and one of them depends on the choice of the other. When you select one value of the first component of the menu, the second changes with the event onchange="submit()"and the valueChangeListener="#{Usuario.cmbDatos_action}"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>
This is similar to the 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 to load the next menu. I tried this as follows:
public String cmbDatos_action() {
try {
int intValor = Integer.parseInt(cmbDatos.getValue().toString());
} catch(Exception ex) {
}
return null;
}
In which part of the method cmbDatos_action()can I put the code to load the second menu?
source
share