2 Replies Latest reply: Sep 26, 2008 4:12 AM by 658179 RSS

    preselection in af:selectmany

    658179
      Hi,

      I did find this thread about preselection of af:selectManyListBoxes, but I didn't really understand the answer.

      how to : pre select values in SelectManyListBox

      Can someone give me a hint with this. I did ask for help in the other thread, but it doesn't seem that anyone is taking a look at it anymore, because it is already marked as "Correctly Answered".

      I did use the blog of Frank Nimphius (ADF Faces: Working with the af:selectManyListsbox Part 1 and Part 2), but in the blog there is nothing mentioned about how to preselect different values.

      Thank You
      Bodhy
        • 1. Re: preselection in af:selectmany
          487442
          Hi Bodhy,

          Try the following:

          In the page:
          <af:selectManyCheckbox value="#{bean.selectedElements}" simple="true">
            <f:selectItems value="#{bean.listOfValues}"/>
          </af:selectManyCheckbox>
          In the bean:
          public class MyBean
          {
              private static final List<SelectItem> LOV;
          
              private Collection<String> selected;
          
              static
              {
                  List<SelectItem> temp = new ArrayList<SelectItem>(5);
                  temp.add(new SelectItem("value1", "label1"));
                  temp.add(new SelectItem("value2", "label2"));
                  temp.add(new SelectItem("value3", "label3"));
                  temp.add(new SelectItem("value4", "label4"));
                  temp.add(new SelectItem("value4", "label5"));
          
                  LOV = Collections.unmodifiableList(temp);
              }
          
              public MyBean()
              {
                  selected = new ArrayList<String>();
                  selected.add("value2");
                  selected.add("value5");
              }
          
              public List<SelectItem> getListOfValues()
              {
                  return LOV;
              }
          
              public Collection<String> getSelectedValues()
              {
                  return selected;
              }
          
              public void setSelectedValues(Collection<String> values)
              {
                  this.selected = values;
              }
          }
          Regards,

          ~ Simon
          • 2. Re: preselection in af:selectmany
            658179
            Thank You Simon,

            it is working