7 Replies Latest reply on Apr 9, 2006 7:47 AM by mirko27

    SelectManyCheckbox

    mirko27

      I`m trying to do following:

       <div class="entry">
       <span class="errors">
       <h:message for="roles"/>
       </span>
       <div class="label">
       <h:outputLabel for="roles" value="Õigused"/>
       </div>
       <div class="input">
       <h:selectManyCheckbox id="roles" value="#{user.roles}"
       layout="pageDirection">
       <f:selectItems value="#{rolesMap}"/>
       </h:selectManyCheckbox>
       </div>
       </div>
      In bean:
      @Out
       private Map<String,Role> rolesMap = new HashMap<String,Role>();
      
       @Factory("rolesMap")
       @Begin(join=true)
       public void init() {
      
       List<Role> roles =
       em.createQuery("from Role msg order by msg.rolename desc").getResultList();
      
       Iterator<Role> it = roles.iterator();
       while (it.hasNext()) {
       Role r = it.next();
       rolesMap.put(r.getRolename(),r);
       }
       }
      


      If I try to submit this form then it gives this error: "roles": Value is not a valid option.

      Never used this component before, what am I doing wrong? This is JSF question, I know, but I thought that it should work and maybe seam is stepping in?

        • 1. Re: SelectManyCheckbox
          sunfire

          I am not sure about this and realy like to hear Gavins opinion on my response:

          These attributes occur on component instance variables or property
          accessor methods
          This is taken from the manual for bijection annotations and I take it that bijection annotations only work for Seam components and not for regular types like Map or String?
          So I guess you have to wrap your datamap with some get and set methods and access it in your jsf like this
          <f:selectItems value="#{user.rolesMap}"/>


          I am also not sure if the @Factory annotation would be called since I though the Factory is only used when the variable referenced is null. With your rolesMap being initialized with an HashMap object I'd think it would never get called unless you'd set it null somwhere else?

          But as I mentioned this is me guessing before heaving my first coffee. ;) Somebody else with more knowledge about Seam internals will provide the proper answers I'd say.

          • 2. Re: SelectManyCheckbox
            mirko27

            Factory did get called and rolesMap is in conversational context. It displays verything fine but when I select smth and then submit, then it says this error.

            • 3. Re: SelectManyCheckbox
              sunfire

              Interesting, then I got a whole lot about Seam wrong and hope even more that Gavin or some other Seam guru is going to enlighten us. :(

              • 4. Re: SelectManyCheckbox
                mirko27

                But why doesn`t it like the value options?
                Maybe I Can`t put value as Object n?

                • 5. Re: SelectManyCheckbox
                  gavin.king

                  I don't think the exception is anything at all to do with Seam.

                  Looks like a pure JSF problem. I don't think a Role is a valid value for a SelectItem.

                  What is the stacktrace?

                  • 6. Re: SelectManyCheckbox
                    sunfire

                    selectItems works for me when I use Map<String, String>. Haven't tried to put others things then String into it yet since usualy a selectItem only accepts Strings as value.

                    btw: I had coffee now and no need to point my silly nose on my obvious errors of my first post! Please just ignore it. :/

                    • 7. Re: SelectManyCheckbox
                      mirko27

                      No stack trace, just h: message that it`s not a valid value.
                      Role is an entity bean.