6 Replies Latest reply on Sep 22, 2007 2:09 AM by guisho

    Value not a valid option

      Hi everybody.
      I've been using Richfaces, and let me tell you that I'm really happy with them...it's a superb way to do things.
      But I'm having this little problem that I don't know how to fix, I've been trying for two days and nothing.
      I'm using RichFaces 3.1.0 with myfaces 1.1.5.
      When I use a a4j:commandButton or form, and there is a selectOneMenu inside the form I always get this error message:
      Value is not a valid option.



      Here is my code
      ===
      <h:panelGroup >
      <h:selectOneMenu id="materia_input" value="#{ClientBackingBean.type}" >
      <f:selectItems value="#{ClientBackingBean.typesItems}" />
      <f:selectItem id="test" itemLabel="test" itemValue="3"/>
      </h:selectOneMenu>
      <rich:message errorClass="error" for="materia_input" />
      </h:panelGroup>
      ...

      =====

      I even tried with a test selectItem but still doesn't work. I made some tests and it seems that the value of the selectOneMenu is always null. Any suggestions? Thank you folks.

        • 1. Re: Value not a valid option
          maksimkaszynski

          Looks like some conversion problem. Could you please attach ClientBackingBean source code?

          • 2. Re: Value not a valid option

            Below is the code.
            I also created a custom validator to check the value, and the value is null. It is strange because when I see the rendered page I get to see the listbox correctly. Thanks in advance.

            public SelectItem[] getTypesItems() {
            List list = ClientManager.getList();
            Iterator i = list.iterator();
            List toItem = new ArrayList();
            List toItemDesc = new ArrayList();

            Client next = null;
            while (i.hasNext()) {
            next = (Client) i.next();
            toItem.add(next.getId().toString());
            toItemDesc.add(next.getId().toString());
            }
            return JSFUtils.list2SelectItem(toItem, toItemDesc);
            }

            ======
            JSFUtils.list2SelectItem goes like this:

            public static SelectItem [] list2SelectItem(List list, List label) {
            SelectItem [] toReturn=new SelectItem[list.size()];
            int count=0;
            try {
            Iterator i=list.iterator();
            Iterator i2=label.iterator();
            String str1="";
            String str2="";
            while(i.hasNext()||i2.hasNext()) {
            str1=i.next().toString();
            str2=i2.next().toString();
            System.out.println("str1:<"+str1+"> str2:<"+str2+">");
            toReturn[count]=new SelectItem(str1,str2);
            count++;
            }
            } catch(Exception e) {
            toReturn=null;
            e.printStackTrace();
            }

            return toReturn;
            }
            =====

            • 3. Re: Value not a valid option
              maksimkaszynski

              Still unclear.
              What is the type of #{ClientBackingBean.type} property

              • 4. Re: Value not a valid option

                It is a Long. :)

                • 5. Re: Value not a valid option
                  ilya_shaikovsky

                  You should convert it. Value evaluated to String.

                  • 6. Re: Value not a valid option

                    Hi, thank you for your answers. You were right, my error was a convertion problem. It was not richfaces who caused it, it was myfaces. My code used to work because myfaces wasn't sticking to the JSF specification, but aftwr version 1.1.5 they fixed the error, and throwed it to me.
                    If is it useful for someone read the link in myfaces wiki:
                    http://wiki.apache.org/myfaces/FAQ at the end of the page.

                    Greetings to all, and thank you,

                    Luis