5 Replies Latest reply on Jul 22, 2010 7:12 AM by ilya_shaikovsky

    Get selected value of dynamic combobox.

    deeps83

      Hi all,

       

      In my application I am generating UI components dynamically based on the value that user selects from a combo box.The dynamically generated components are mainly InputNumberSpinner and HtmlComboBox.My requirement is ,based on the values selected in the dynamically generated combobox I want to rerender my UI with some more components.For this I have one method which will be called onlistclose of the dynamic  comboboxes.

      This I have done as shown:

       

      
      

      FacesContext facesContext = FacesContext.getCurrentInstance();

      ELContext elContext = facesContext.getELContext();

      Application application = facesContext.getApplication();

      ExpressionFactory expFactory = application.getExpressionFactory();

      MethodExpression methodExp = expFactory.createMethodExpression

      (elContext,"#{myBean.someFn()}",

      null,

      new Class[] { ActionEvent.class });

      ActionListener aListener =new MethodExpressionActionListener(methodExp);

      HtmlAjaxSupport ajaxSupport =new HtmlAjaxSupport();

      ajaxSupport.addAjaxListener(aListener);

      ajaxSupport.setEvent("onlistclose");

      comboBoxComponent.getChildren().add(ajaxSupport);

      myGrid.getChildren().add(comboBoxComponent);

       

       

       

       

      The function someFn() in the bean calss is getting called on list close of dynamic combo boxes.But how can I get the selected values of the dynamic comboboxes in the function so that I can decide on what should be done next?

       

      If anyone have any idea please help.

       

      Thanks in advance,

      Deeps.

        • 1. Re: Get selected value of dynamic combobox.
          ilya_shaikovsky

          when actionListener is called - new value of comboBox already populated to model bean. you could just get it from there.

          • 2. Re: Get selected value of dynamic combobox.
            deeps83

            Hi Ilya,

            Thanks for the reply.

            Yes, in noraml case that will be how it works.But my problem is like,

            suppose user has selected a value 'A'  from one main combobox ,then I will be having say some 10 components of which some will be HtmlComboBox and some will be HtmlInputNumber spinner .If the user selects another value say 'B' there will be another set of components that needs to be shown.I am creating these components dynamically and adding to one HtmlGrid which is having a binding with an HmlGrid in my bean class and rerendering.Since these components are created dynamically there will not be an attribute in the bean corresponding to the value of each component.So I have no option to get the value in this way.

             

            Hope you got my problem.Pleas let me know if I can have a solution for this.

             

            thanks,

            Deeps.

            • 3. Re: Get selected value of dynamic combobox.
              ilya_shaikovsky

              I see... but the comboBox which change should affect the dynamic part of UI being submitted. And it has current Value already set. And it populates ValueChange Event which also contains this new value.. So not sure.. seems still not getting the problem.

              • 4. Re: Get selected value of dynamic combobox.
                deeps83

                Hi,

                 

                So you mean to say, I have to add a valueChangeListener for the HtmlComboBoxes that I am creating dynamically ,and in the valueChangeListener method the new value of the component will be available as component.getNewValue()?

                 

                ok.But I am not sure how I can add a value change listener dynamically.If you dont mind can you please give a sample code for the same.

                 

                Thanks,

                Deeps.

                • 5. Re: Get selected value of dynamic combobox.
                  ilya_shaikovsky

                  just even.getNewValue