Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8770451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:33:41+00:00 2026-06-13T17:33:41+00:00

I have a <t:dataTable> with two <h:selectOneMenu> dropdowns in two columns. The second dropdown

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:33:41+00:00Added an answer on June 13, 2026 at 5:33 pm

    Your concrete problem is caused because the list of the 2nd dropdown in the last column is been bound to one and same bean property and in no way dependent of the current row.

    In this construct, your best bet would be passing the currently selected value of the 1st dropdown to the <f:selectItems> of the 2nd 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 render="seleccionCampoCorrespondido"/>
            </h:selectOneMenu>
        </t:column>
        <t:column>
            <h:selectOneMenu id="seleccionCampoCorrespondido" value="#{item.columnaCorr}">
                <f:selectItems id="listaCampoCorrespondido" value="#{tablaConfigBean.getCamposList(item.tabla)}" var="campo" itemValue="#{campo}"/>
            </h:selectOneMenu>
        </t:column>
    </t:dataTable>
    

    (I removed the <f:ajax listener> from the 1st dropdown and I changed the <f:selectItems value> of the 2nd dropdown)

    And move the original ajax listener method’s job to the getter behind <f:selectItems>.

    private Map<Tabla, List<Campo>> tablaCampos = new HashMap<Tabla, List<Campo>>();
    
    public List<Campo> getCamposList(Tabla tablaParaCampos) {
        List<Campo> campos = tableCampos.get(tablaParaCampos);
    
        if (campos == null) {
            campos = cDAOtablaConfig.rellenaCamposTabla(idSistema, sistema.desEsquema, tablaParaCampos, 3);
            tableCampos.put(table, campos);
        }
    
        return campos;
    }
    

    Note that lazy loading + cache is implemented here. Also note that you should make sure that the equals() and hashCode() of Tabla class are properly implemented.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two DataTables. First is DataTable NameAddressPhones = new DataTable(); with Three columns
I have a dropdown. I need to bind with two field of datatable value
I have two datatable , first contain DataTable dtMaterialStatement = new DataTable(); dtMaterialStatement.Columns.Add(new DataColumn(MaterialNo,
I have two datatable, while adding rows in second datatable, I want to first
I have a Primefaces dataTable with rowEdit. Two columns contain a selectOneMenu control in
I have a datatable with two columns, Column 1 = EmpID Column 2 =
I'm using Visual Studio 2005 and have a DataTable with two columns and some
I have a DataTable containing two columns, both of which is a list of
So I am practicing using a databases with ASP.Net... I have two datatable columns
var id = Session[staff_id].ToString() //I have datatable with 5 columns DataTable dt = function_return_Datatable(id);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.