I have a <t:dataTable>
with two <h:selectOneMenu>
dropdowns in two columns. The second dropdown is populated depending on the value of the first dropdown.
<t:dataTable value="#{tablaConfigBean.tablaConfigList}" var="item">
<t:column>
<h:selectOneMenu value="#{item.tabla}">
<f:selectItem itemLabel="SIN CORRESPONDENCIA" itemValue="SIN CORRESPONDENCIA"/>
<f:selectItems value="#{tablaConfigBean.tablasList}" var="tabla" itemLabel="#{tabla}" itemValue="#{tabla}"/>
<f:ajax listener="#{tablaConfigBean.rellenaCampos}" render="seleccionCampoCorrespondido"/>
</h:selectOneMenu>
</t:column>
<t:column>
<h:selectOneMenu id="seleccionCampoCorrespondido" value="#{item.columnaCorr}">
<f:selectItems id="listaCampoCorrespondido" value="#{tablaConfigBean.camposList}" var="campo" itemValue="#{campo}"/>
</h:selectOneMenu>
</t:column>
</t:dataTable>
Bean:
public void rellenaCampos (AjaxBehaviorEvent event) throws Exception {
dataTable = (HtmlDataTable) event.getComponent().getParent().getParent();
fila = (cCNtablaConfig) dataTable.getRowData();
tablaParaCampos = fila.getTabla();
camposList = cDAOtablaConfig.rellenaCamposTabla(idSistema, sistema.desEsquema, tablaParaCampos, 3);
}
Although the first dropdown dosen't have any value, its <f:selectItems>
is always loaded by default. If I choose one of those values, then the <f:selectItems>
of the second dropdown populates. The problem appears when the both <h:selectOneMenu>
s have to show a value preinitialized from the database. As I have written it, the second dropdown is not loaded with the corresponding value unless I choose manually the value on the first dropdown. Then, the expected value appears.
I have tried something like this: Execute managebean method from javascript onload event, but I'm not able to make it work. How can I do this?