2 Replies Latest reply on May 13, 2007 2:38 PM by Saif KHan

    Problem using selectOneMenu in jenerating dynamic select opt

    Saif KHan Newbie

      Dear fellows,

      I am getting a strange problem, I have a form for adding a new hotel in db. I have two selectOneMenu in my forms.
      1. country
      2. states

      when the value of country is selected, i use seam remoting to get the states of that country and populate in my second list states. And i submit the form, untill here there are no problems.

      but when i submit the form get a validation message for the states list box, "value is not valid". I dont know why it is giving it. Here is some description of my code in javascript.

      function loadCountryStates(){
      
       var str = document.getElementById('hotelform:country').value;
       HotelsAction.getCountryStatesList(str,getStatesCallback);
      
      }
      
      function getStatesCallback(result){
       clearStatesList();
      
       var resLen = result.length;
      
       for(var i=0; i < resLen ; i ++){
      
       var codeName = result;
       var code = codeName[0];
       var name = codeName[1];
      
       var states = document.getElementById('hotelform:state');
      
       newOpt = document.createElement('option');
       newOpt.value = code;
       newOpt.text = name;
      
       try {
       states.add(newOpt, null); // standards compliant; doesn't work in IE
       }catch(ex) {
       states.add(newOpt); // IE only
       }
       }
       }
      

      THis is the way i am populating my list and it give following error on the console output

      17:47:37,468 ERROR [NavigationMenuUtils] Invalid child with id _id2of component with id : nav_3 : must be UINavigationMenuItem or UINavigationMenuItems, is of type : com.sun.facelets.compiler.UIInstructions


      Can any one help me thanx in advance

        • 1. Re: Problem using selectOneMenu in jenerating dynamic select
          Monkey Den Master

          In JSF, it is required that the submitted values for select boxes are a subset of the original SelectItems. In other words, if you have values 1,2,3,4,5 displayed in a select box, the submitted values need to be some subset of 1,2,3,4,5, and any value other than these is invalid. You have a few options:

          1. In the value change listener, try to modify the list the receiving selectbox uses and use immediate=true on it. I haven't gotten this to work. JSF doesn't update the values in the component tree for some reason.

          2. Write your own JSF component which consists of two select boxes and two buttons (Add/Remove), something like the Tomahawk component.
          http://www.irian.at/myfaces-sandbox/picklist.jsf

          3. Do it strictly client side, parse the values in JavaScript and submit in a hidden field, and parse on the server side. This is the most distasteful.

          • 2. Re: Problem using selectOneMenu in jenerating dynamic select
            Saif KHan Newbie

            thank you dear for your help,

            I have 2 drop down lists:

            1. country
            2. states

            In the first list of country i use a factory method retuning selectItems to jsf component. when any country from the list is selected i use seam remoting to tranfer the country to EJBs and get the respective states in seam remoting. then i parse the result in javascript and i update the jsf 2nd selectOneMenu.I am not using jsf valueChangeEvent.

            untill here all of the values populate in the list successfully.
            but when i submit the values, the state component give me error message "value is not valid".

            I dont know why it is telling that the value is invalid when the process that i did was working fine, accept the error message.

            thank you,