5 Replies Latest reply on Dec 1, 2008 3:16 PM by nbelaevski

    Update rich:comboBox

    richy

      Hello,

      First of all, i'm sorry about my english, but i'm french.

      I am currently using the rich:comboBox component and i have a little problem :

      In my jsf page, there are 3 comboBox, but only the first one is initialized thanks to a database. When a user selects something in the first comboBox, i'd like that update the second combobox, and when he selects something in the second combobox, i'd like that update the third one.
      I hope someone will understand what i would like XD


      This is how my database is build :
      Table csp_n1 (2columns) :
      - code_csp_n1
      - libelle

      Table csp_n2 (3 columns) :
      - code_csp_n2
      - libelle
      - code_csp_n1

      Table csp_n3 (3 columns) :
      - code_csp_n3
      - libelle
      - code_csp_n2

      I tried many things, but it never works correctly.
      Do anyone have an idea how i could do please ?

        • 1. Re: Update rich:comboBox
          richy

          This is what i tried :

          <rich:comboBox id="csp1" value="#{TableCsp.csp1Selected}" suggestionValues="#{TableCsp.test}"
           directInputSuggestions="true" defaultLabel="Sélectionner une csp">
           <a4j:support event="onselect" reRender="csp2" action="#{TableCsp.updateCsp2}"/>
           </rich:comboBox>
          
          <rich:comboBox id="csp2" suggestionValues="#{TableCsp.test2}"
           directInputSuggestions="true" defaultLabel="Sélectionner une csp">
           </rich:comboBox>


          and my TableCsp.java :
          public class TableCsp {
          
           List<String> test;
           String csp1Selected;
          
           List<String> test2;
           String csp2Selected;
          
           DBConnection db;
           Connection conn;
           Statement stat;
           String query;
          
          
           public TableCsp() throws SQLException {
           test = new ArrayList<String>();
           test2 = new ArrayList<String>();
          
           db = new DBConnection();
           conn = db.getConnection();
           stat = conn.createStatement();
           query = "SELECT * FROM csp_n1 ";
           ResultSet rs = stat.executeQuery(query);
           while(rs.next()){
           test.add(rs.getString("libelle"));
           }
           }
          
           public void updateCsp2() throws SQLException{
           query = "SELECT * FROM csp_n1 WHERE libelle = '"+csp1Selected+"'";
           ResultSet rs = stat.executeQuery(query);
           rs.next();
           String code = rs.getString("code_csp_n1");
          
           query = "SELECT * FROM csp_n2 WHERE code_csp_n1 = '"+code+"'";
           rs = stat.executeQuery(query);
           while(rs.next()){
           test2.add(rs.getString("libelle"));
           }
           }


          • 2. Re: Update rich:comboBox
            richy

            I added immediate="true" in the rich:combobox and in the a4j:support, and now it goes in function updateCsp2. But the problem is that csp1Selected is always null, so the request cant work :/

            • 3. Re: Update rich:comboBox
              richy

              I finally done it using a binding property on my combobox component :D

              • 4. Re: Update rich:comboBox
                strannik

                Unfortunately the last workaround doesn't work with me :(

                When action(bean.update) on the server side occurs the combobox value is not submitted yet and year is null. Is there any way to perform AJAX requests and have combobox value submitted?

                <rich:comboBox value="#{bean.year}" id="year" immediate="true" binding="#{bean.component}">
                 <f:selectItem itemValue="2009" />
                 <f:selectItem itemValue="2008" />
                 <f:selectItem itemValue="2007" />
                 <a4j:support event="onblur" reRender="comp" immediate="true"
                 action="#{bean.update}" />
                 </rich:comboBox>
                


                • 5. Re: Update rich:comboBox
                  nbelaevski

                  Hello,

                  Try onselect in combination with onkeyup