public void restoreState(FacesContext _context, Object _state) {
   Object _values[] = (Object[]) _state;
   super.restoreState(_context, _values[0]);
   this.accesskey = (java.lang.String) _values[1];
   this.border = ((Integer) _values[2]).intValue();
   this.border_set = ((Boolean) _values[3]).booleanValue();
   this.dir = (java.lang.String) _values[4];
   this.disabled = ((Boolean) _values[5]).booleanValue();
   this.disabled_set = ((Boolean) _values[6]).booleanValue();
   this.disabledClass = (java.lang.String) _values[7];
   this.enabledClass = (java.lang.String) _values[8];
   this.lang = (java.lang.String) _values[9];
   this.layout = (java.lang.String) _values[10];
   this.onblur = (java.lang.String) _values[11];
   this.onchange = (java.lang.String) _values[12];
   this.onclick = (java.lang.String) _values[13];
   this.ondblclick = (java.lang.String) _values[14];
   this.onfocus = (java.lang.String) _values[15];
   this.onkeydown = (java.lang.String) _values[16];
   this.onkeypress = (java.lang.String) _values[17];
   this.onkeyup = (java.lang.String) _values[18];
   this.onmousedown = (java.lang.String) _values[19];
   this.onmousemove = (java.lang.String) _values[20];
   this.onmouseout = (java.lang.String) _values[21];
   this.onmouseover = (java.lang.String) _values[22];
   this.onmouseup = (java.lang.String) _values[23];
   this.onselect = (java.lang.String) _values[24];
   this.readonly = ((Boolean) _values[25]).booleanValue();
   this.readonly_set = ((Boolean) _values[26]).booleanValue();
   this.style = (java.lang.String) _values[27];
   this.styleClass = (java.lang.String) _values[28];
   this.tabindex = (java.lang.String) _values[29];
   this.title = (java.lang.String) _values[30];
 }
Beispiel #2
0
 public static void shiftItemsLast(
     UISelectMany targetSelect, UISelectItems targetItems, UIEditableList hiddenTargetList) {
   String[] selected = (String[]) targetSelect.getSelectedValues();
   SelectItem[] all = (SelectItem[]) targetItems.getValue();
   if (selected == null) {
     // nothing to do
     return;
   }
   all = shiftLast(selected, all);
   targetItems.setValue(all);
   clearTargetList(hiddenTargetList);
   addToTargetList(hiddenTargetList, all);
 }
 @Override
 protected String getSubmitParam(FacesContext context, UISelectMany selectMany) {
   return selectMany.getClientId(context) + "_input";
 }
Beispiel #4
0
  public void testUISelectMany() throws Exception {
    // create the test bean
    TestBean bean = new TestBean();
    getFacesContext().getExternalContext().getRequestMap().put("bean", bean);
    // create a dummy root for the tree.
    UIViewRoot root = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null);
    root.setId("root");
    root.setLocale(Locale.US);
    getFacesContext().setViewRoot(root);

    // test model type of boolean []
    UISelectMany booleanv = new UISelectMany();
    booleanv.setId("bool");
    booleanv.setRendererType("javax.faces.Checkbox");
    booleanv.setValueExpression(
        "value",
        (getFacesContext()
            .getApplication()
            .getExpressionFactory()
            .createValueExpression(
                getFacesContext().getELContext(), "#{bean.booleans}", Boolean.class)));
    root.getChildren().add(booleanv);
    booleanv.getChildren().add(newUISelectItem(Boolean.TRUE));
    booleanv.getChildren().add(newUISelectItem(Boolean.FALSE));
    booleanv.decode(getFacesContext());
    booleanv.validate(getFacesContext());
    booleanv.updateModel(getFacesContext());
    assertNotNull(bean.getBooleans());
    assertTrue(bean.getBooleans()[0] == false);
    assertTrue(bean.getBooleans()[1] == true);
    assertTrue(bean.getBooleans()[2] == false);

    // test model type of boolean []
    booleanv = new UISelectMany();
    booleanv.setId("bool2");
    booleanv.setRendererType("javax.faces.Checkbox");
    booleanv.setValueExpression(
        "value",
        (getFacesContext()
            .getApplication()
            .getExpressionFactory()
            .createValueExpression(
                getFacesContext().getELContext(), "#{bean.booleans}", Object.class)));
    root.getChildren().add(booleanv);
    booleanv.getChildren().add(newUISelectItem(Boolean.TRUE));
    booleanv.getChildren().add(newUISelectItem(Boolean.FALSE));
    booleanv.decode(getFacesContext());
    booleanv.validate(getFacesContext());
    booleanv.updateModel(getFacesContext());
    assertNotNull(bean.getBooleans());
    assertTrue(bean.getBooleans()[0] == false);
    assertTrue(bean.getBooleans().length == 1);

    // test model type of byte []
    UISelectMany bytev = new UISelectMany();
    bytev.setId("byte");
    bytev.setRendererType("javax.faces.Checkbox");

    bytev.setValueExpression(
        "value",
        getFacesContext()
            .getApplication()
            .getExpressionFactory()
            .createValueExpression(
                getFacesContext().getELContext(), "#{bean.bytes}", Object.class));
    bytev.getChildren().add(newUISelectItem(new Byte(Byte.MIN_VALUE)));
    bytev.getChildren().add(newUISelectItem(new Byte(Byte.MAX_VALUE)));
    bytev.getChildren().add(newUISelectItem(new Byte((byte) 1)));
    bytev.getChildren().add(newUISelectItem(new Byte((byte) -1)));
    root.getChildren().add(bytev);
    bytev.decode(getFacesContext());
    bytev.validate(getFacesContext());
    bytev.updateModel(getFacesContext());
    assertNotNull(bean.getBytes());
    assertTrue(bean.getBytes()[0] == Byte.MIN_VALUE);
    assertTrue(bean.getBytes()[1] == Byte.MAX_VALUE);
    assertTrue(bean.getBytes()[2] == 1);

    // test model type of char []
    UISelectMany charv = new UISelectMany();
    charv.setId("char");
    charv.setRendererType("javax.faces.Checkbox");
    charv.setValueExpression(
        "value",
        getFacesContext()
            .getApplication()
            .getExpressionFactory()
            .createValueExpression(
                getFacesContext().getELContext(), "#{bean.chars}", Object.class));
    root.getChildren().add(charv);
    charv.getChildren().add(newUISelectItem(new Character('Q')));
    charv.getChildren().add(newUISelectItem(new Character('A')));
    charv.getChildren().add(newUISelectItem(new Character('Z')));
    charv.getChildren().add(newUISelectItem(new Character('z')));
    charv.decode(getFacesContext());
    charv.validate(getFacesContext());
    charv.updateModel(getFacesContext());
    assertNotNull(bean.getChars());
    assertTrue(bean.getChars()[0] == 'Q');
    assertTrue(bean.getChars()[1] == 'A');
    assertTrue(bean.getChars()[2] == 'z');

    // test model type of short []
    UISelectMany shortv = new UISelectMany();
    shortv.setId("short");
    shortv.setRendererType("javax.faces.Checkbox");
    shortv.setValueExpression(
        "value",
        getFacesContext()
            .getApplication()
            .getExpressionFactory()
            .createValueExpression(
                getFacesContext().getELContext(), "#{bean.shorts}", Object.class));
    root.getChildren().add(shortv);
    shortv.getChildren().add(newUISelectItem(new Short((short) (Byte.MAX_VALUE + 1))));
    shortv.getChildren().add(newUISelectItem(new Short((short) 100)));
    shortv.getChildren().add(newUISelectItem(new Short(Short.MIN_VALUE)));
    shortv.getChildren().add(newUISelectItem(new Short(Short.MAX_VALUE)));
    shortv.decode(getFacesContext());
    shortv.validate(getFacesContext());
    shortv.updateModel(getFacesContext());
    assertNotNull(bean.getShorts());
    assertTrue(bean.getShorts()[0] == Short.MIN_VALUE);
    assertTrue(bean.getShorts()[1] == Short.MAX_VALUE);
    assertTrue(bean.getShorts()[2] == Byte.MAX_VALUE + 1);

    // test model type of int []
    UISelectMany intv = new UISelectMany();
    intv.setId("int");
    intv.setRendererType("javax.faces.Checkbox");
    intv.setValueExpression(
        "value",
        getFacesContext()
            .getApplication()
            .getExpressionFactory()
            .createValueExpression(getFacesContext().getELContext(), "#{bean.ints}", Object.class));
    root.getChildren().add(intv);
    intv.getChildren().add(newUISelectItem(new Integer(Short.MAX_VALUE + 1)));
    intv.getChildren().add(newUISelectItem(new Integer(100)));
    intv.getChildren().add(newUISelectItem(new Integer(Integer.MIN_VALUE)));
    intv.getChildren().add(newUISelectItem(new Integer(Integer.MAX_VALUE)));
    intv.decode(getFacesContext());
    intv.validate(getFacesContext());
    intv.updateModel(getFacesContext());
    assertNotNull(bean.getInts());
    assertTrue(bean.getInts()[0] == Integer.MIN_VALUE);
    assertTrue(bean.getInts()[1] == Integer.MAX_VALUE);
    assertTrue(bean.getInts()[2] == Short.MAX_VALUE + 1);

    // test model type of float []
    UISelectMany floatv = new UISelectMany();
    floatv.setId("float");
    floatv.setRendererType("javax.faces.Checkbox");
    floatv.setValueExpression(
        "value",
        getFacesContext()
            .getApplication()
            .getExpressionFactory()
            .createValueExpression(
                getFacesContext().getELContext(), "#{bean.floats}", Object.class));
    root.getChildren().add(floatv);
    floatv.getChildren().add(newUISelectItem(new Float(Integer.MAX_VALUE + 1)));
    floatv.getChildren().add(newUISelectItem(new Float(100)));
    floatv.getChildren().add(newUISelectItem(new Float(Float.MIN_VALUE)));
    floatv.getChildren().add(newUISelectItem(new Float(Float.MAX_VALUE)));
    floatv.decode(getFacesContext());
    floatv.validate(getFacesContext());
    floatv.updateModel(getFacesContext());
    assertNotNull(bean.getFloats());
    assertTrue(bean.getFloats()[0] == Float.MIN_VALUE);
    assertTrue(bean.getFloats()[1] == Float.MAX_VALUE);
    assertTrue(bean.getFloats()[2] == Integer.MAX_VALUE + 1);

    // test model type of long []
    UISelectMany longv = new UISelectMany();
    longv.setId("long");
    longv.setRendererType("javax.faces.Checkbox");
    longv.setValueExpression(
        "value",
        getFacesContext()
            .getApplication()
            .getExpressionFactory()
            .createValueExpression(
                getFacesContext().getELContext(), "#{bean.longs}", Object.class));
    root.getChildren().add(longv);
    longv.getChildren().add(newUISelectItem(new Long(Integer.MAX_VALUE + 1)));
    longv.getChildren().add(newUISelectItem(new Long(100)));
    longv.getChildren().add(newUISelectItem(new Long(Long.MIN_VALUE)));
    longv.getChildren().add(newUISelectItem(new Long(Long.MAX_VALUE)));
    longv.decode(getFacesContext());
    longv.validate(getFacesContext());
    longv.updateModel(getFacesContext());
    assertNotNull(bean.getLongs());
    assertTrue(bean.getLongs()[0] == Long.MIN_VALUE);
    assertTrue(bean.getLongs()[1] == Long.MAX_VALUE);
    assertTrue(bean.getLongs()[2] == Integer.MAX_VALUE + 1);

    // test model type of double []
    UISelectMany doublev = new UISelectMany();
    doublev.setId("double");
    doublev.setRendererType("javax.faces.Checkbox");
    doublev.setValueExpression(
        "value",
        getFacesContext()
            .getApplication()
            .getExpressionFactory()
            .createValueExpression(
                getFacesContext().getELContext(), "#{bean.doubles}", Object.class));
    root.getChildren().add(doublev);
    doublev.getChildren().add(newUISelectItem(new Double(Long.MAX_VALUE + 1)));
    doublev.getChildren().add(newUISelectItem(new Double(100)));
    doublev.getChildren().add(newUISelectItem(new Double(Double.MIN_VALUE)));
    doublev.getChildren().add(newUISelectItem(new Double(Double.MAX_VALUE)));
    doublev.decode(getFacesContext());
    doublev.validate(getFacesContext());
    doublev.updateModel(getFacesContext());
    assertNotNull(bean.getDoubles());
    assertTrue(bean.getDoubles()[0] == Double.MIN_VALUE);
    assertTrue(bean.getDoubles()[1] == Double.MAX_VALUE);
    assertTrue(bean.getDoubles()[2] == Long.MAX_VALUE + 1);

    // test model type of String []
    UISelectMany str = new UISelectMany();
    str.setId("str");
    str.setRendererType("javax.faces.Checkbox");
    str.setValueExpression(
        "value",
        getFacesContext()
            .getApplication()
            .getExpressionFactory()
            .createValueExpression(
                getFacesContext().getELContext(), "#{bean.strings}", Object.class));
    root.getChildren().add(str);
    str.getChildren().add(newUISelectItem("value1"));
    str.getChildren().add(newUISelectItem("value2"));
    str.getChildren().add(newUISelectItem("value3"));
    str.getChildren().add(newUISelectItem("value4"));
    str.decode(getFacesContext());
    str.validate(getFacesContext());
    str.updateModel(getFacesContext());
    assertNotNull(bean.getStrings());
    assertTrue("value1".equals(bean.getStrings()[0]));

    // test model type of Date []
    UISelectMany date = new UISelectMany();
    Converter dateConv = Util.getConverterForIdentifer("javax.faces.DateTime", getFacesContext());
    assertNotNull(dateConv);
    date.setConverter(dateConv);
    date.setId("date");
    date.setRendererType("javax.faces.Checkbox");
    date.setValueExpression(
        "value",
        getFacesContext()
            .getApplication()
            .getExpressionFactory()
            .createValueExpression(
                getFacesContext().getELContext(), "#{bean.dates}", Object.class));
    root.getChildren().add(date);

    try {
      SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
      df.setTimeZone(TimeZone.getTimeZone("GMT"));
      date.getChildren().add(newUISelectItem(df.parse("19670101")));
      date.getChildren().add(newUISelectItem(df.parse("20030526")));
      date.getChildren().add(newUISelectItem(df.parse("19460819")));
      date.getChildren().add(newUISelectItem(df.parse("17760704")));
    } catch (ParseException e) {
      assertTrue(e.getMessage(), false);
    }

    date.decode(getFacesContext());
    date.validate(getFacesContext());
    date.updateModel(getFacesContext());
    assertNotNull(bean.getDates());
    Object expected = null;
    try {
      SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
      df.setTimeZone(TimeZone.getTimeZone("GMT"));
      expected = df.parse("19460819");
    } catch (ParseException e) {
      assertTrue(e.getMessage(), false);
    }
    assertEquals("bean.getDates()[2] not as expected: ", expected, bean.getDates()[2]);

    // test model type of Number []
    UISelectMany number = new UISelectMany();
    Converter numberConv = Util.getConverterForIdentifer("javax.faces.Number", getFacesContext());
    assertNotNull(numberConv);
    number.setConverter(numberConv);
    number.setId("num");
    number.setRendererType("javax.faces.Checkbox");
    number.setValueExpression(
        "value",
        getFacesContext()
            .getApplication()
            .getExpressionFactory()
            .createValueExpression(
                getFacesContext().getELContext(), "#{bean.numbers}", Object.class));
    root.getChildren().add(number);
    number.getChildren().add(newUISelectItem(new Double(3.14)));
    number.getChildren().add(newUISelectItem(new Double(49.99)));
    number.getChildren().add(newUISelectItem(new Long(12)));
    number.getChildren().add(newUISelectItem(new Double(-145.5)));
    number.decode(getFacesContext());
    number.validate(getFacesContext());
    number.updateModel(getFacesContext());
    assertNotNull(bean.getNumbers());
    try {
      DecimalFormat df = new DecimalFormat("'$'##.##", new DecimalFormatSymbols(Locale.US));
      expected = df.parse("$49.99");
    } catch (ParseException e) {
      assertTrue(e.getMessage(), false);
    }
    assertTrue(expected.equals(bean.getNumbers()[2]));

    // test model type of List of Strings
    UISelectMany stringList = new UISelectMany();
    stringList.setId("stringList");
    stringList.setRendererType("javax.faces.Checkbox");
    stringList.setValueExpression(
        "value",
        getFacesContext()
            .getApplication()
            .getExpressionFactory()
            .createValueExpression(
                getFacesContext().getELContext(), "#{bean.stringList}", Object.class));
    root.getChildren().add(stringList);
    stringList.getChildren().add(newUISelectItem("value1"));
    stringList.getChildren().add(newUISelectItem("value2"));
    stringList.getChildren().add(newUISelectItem("value3"));
    stringList.getChildren().add(newUISelectItem("value4"));
    stringList.decode(getFacesContext());
    stringList.validate(getFacesContext());
    stringList.updateModel(getFacesContext());
    assertNotNull(bean.getStringList());
    assertTrue(bean.getStringList().get(0).equals("value1"));
    assertTrue(bean.getStringList().get(1).equals("value2"));
    assertTrue(bean.getStringList().get(2).equals("value3"));
  }
Beispiel #5
0
  /** Move items from components to others. */
  public static void moveItems(
      UISelectMany sourceSelect,
      UISelectItems sourceItems,
      UISelectItems targetItems,
      UIEditableList hiddenTargetList,
      boolean setTargetIds) {
    String[] selected = (String[]) sourceSelect.getSelectedValues();
    if (selected == null) {
      // nothing to do
      return;
    }
    List<String> selectedList = Arrays.asList(selected);

    SelectItem[] all = (SelectItem[]) sourceItems.getValue();
    List<SelectItem> toMove = new ArrayList<SelectItem>();
    List<SelectItem> toKeep = new ArrayList<SelectItem>();
    List<String> hiddenIds = new ArrayList<String>();
    if (all != null) {
      for (SelectItem item : all) {
        String itemId = item.getValue().toString();
        if (selectedList.contains(itemId)) {
          toMove.add(item);
        } else {
          toKeep.add(item);
          if (!setTargetIds) {
            hiddenIds.add(itemId);
          }
        }
      }
    }
    // reset left values
    sourceItems.setValue(toKeep.toArray(new SelectItem[] {}));
    sourceSelect.setSelectedValues(new Object[0]);

    // change right values
    List<SelectItem> newSelectItems = new ArrayList<SelectItem>();
    SelectItem[] oldSelectItems = (SelectItem[]) targetItems.getValue();
    if (oldSelectItems == null) {
      newSelectItems.addAll(toMove);
    } else {
      newSelectItems.addAll(Arrays.asList(oldSelectItems));
      List<String> oldIds = new ArrayList<String>();
      for (SelectItem oldItem : oldSelectItems) {
        String id = oldItem.getValue().toString();
        oldIds.add(id);
      }
      if (setTargetIds) {
        hiddenIds.addAll(0, oldIds);
      }
      for (SelectItem toMoveItem : toMove) {
        String id = toMoveItem.getValue().toString();
        if (!oldIds.contains(id)) {
          newSelectItems.add(toMoveItem);
          if (setTargetIds) {
            hiddenIds.add(id);
          }
        }
      }
    }
    targetItems.setValue(newSelectItems.toArray(new SelectItem[] {}));

    // update hidden values
    int numValues = hiddenTargetList.getRowCount();
    if (numValues > 0) {
      for (int i = numValues - 1; i > -1; i--) {
        hiddenTargetList.removeValue(i);
      }
    }
    for (String newHiddenValue : hiddenIds) {
      hiddenTargetList.addValue(newHiddenValue);
    }
  }