use of jakarta.faces.component.UISelectOne in project myfaces by apache.
the class HtmlRendererUtils method getSubmittedOrSelectedValuesAsSet.
public static Set getSubmittedOrSelectedValuesAsSet(boolean selectMany, UIComponent uiComponent, FacesContext facesContext, Converter converter) {
Set lookupSet;
if (selectMany) {
UISelectMany uiSelectMany = (UISelectMany) uiComponent;
lookupSet = RendererUtils.getSubmittedValuesAsSet(facesContext, uiComponent, converter, uiSelectMany);
if (lookupSet == null) {
lookupSet = RendererUtils.getSelectedValuesAsSet(facesContext, uiComponent, converter, uiSelectMany);
}
} else {
UISelectOne uiSelectOne = (UISelectOne) uiComponent;
Object lookup = uiSelectOne.getSubmittedValue();
if (lookup == null) {
lookup = uiSelectOne.getValue();
String lookupString = RendererUtils.getConvertedStringValue(facesContext, uiComponent, converter, lookup);
lookupSet = Collections.singleton(lookupString);
} else if (RendererUtils.EMPTY_STRING.equals(lookup)) {
lookupSet = Collections.EMPTY_SET;
} else {
lookupSet = Collections.singleton(lookup);
}
}
return lookupSet;
}
use of jakarta.faces.component.UISelectOne in project myfaces by apache.
the class UISelectItemsTest method testPrimitiveArrayAsValue.
public void testPrimitiveArrayAsValue() {
int[] value = new int[3];
value[0] = 1;
value[1] = 2;
value[2] = 3;
UISelectItems selectItems = new UISelectItems();
selectItems.setValue(value);
selectItems.getAttributes().put("var", "item");
ValueExpression itemValue = new MockValueExpression("#{item}", Object.class);
selectItems.setValueExpression("itemValue", itemValue);
UISelectOne selectOne = new UISelectOne();
selectOne.getChildren().add(selectItems);
SelectItemsIterator iter = new SelectItemsIterator(selectOne, facesContext);
int[] options = new int[3];
for (int i = 0; i < 3; i++) {
options[i] = (Integer) iter.next().getValue();
// test equality
Assert.assertEquals(value[i], options[i]);
}
}
use of jakarta.faces.component.UISelectOne in project myfaces by apache.
the class UISelectOneTest method testValidateNotRequiredNotSelectOption.
@Test
public void testValidateNotRequiredNotSelectOption() {
facesContext.getViewRoot().setLocale(_TEST_LOCALE);
UISelectOne selectOne = new UISelectOne();
selectOne.setId("selectOne");
selectOne.setRendererType(null);
selectOne.setRequired(false);
List<UIComponent> children = selectOne.getChildren();
UISelectItem one = new UISelectItem();
one.setItemValue(new Integer(1));
children.add(one);
UISelectItem two = new UISelectItem();
two.setItemValue(new Integer(2));
children.add(two);
UISelectItem three = new UISelectItem();
three.setItemValue(new Integer(3));
three.setNoSelectionOption(true);
children.add(three);
selectOne.validateValue(facesContext, 3);
Assert.assertTrue(selectOne.isValid());
Assert.assertEquals(0, facesContext.getMessageList().size());
}
use of jakarta.faces.component.UISelectOne in project myfaces by apache.
the class UISelectOneTest method testValidateRequiredNotSelectOption.
@Test
public void testValidateRequiredNotSelectOption() {
facesContext.getViewRoot().setLocale(_TEST_LOCALE);
UISelectOne selectOne = new UISelectOne();
selectOne.setId("selectOne");
selectOne.setRendererType(null);
selectOne.setRequired(true);
List<UIComponent> children = selectOne.getChildren();
UISelectItem one = new UISelectItem();
one.setItemValue(new Integer(1));
children.add(one);
UISelectItem two = new UISelectItem();
two.setItemValue(new Integer(2));
children.add(two);
UISelectItem three = new UISelectItem();
three.setItemValue(new Integer(3));
three.setNoSelectionOption(true);
children.add(three);
selectOne.validateValue(facesContext, 3);
Assert.assertFalse(selectOne.isValid());
Assert.assertEquals(1, facesContext.getMessageList().size());
}
use of jakarta.faces.component.UISelectOne in project myfaces by apache.
the class UISelectOneTest method testValidateNotRequiredValid.
@Test
public void testValidateNotRequiredValid() {
facesContext.getViewRoot().setLocale(_TEST_LOCALE);
UISelectOne selectOne = new UISelectOne();
selectOne.setId("selectOne");
selectOne.setRendererType(null);
selectOne.setRequired(false);
List<UIComponent> children = selectOne.getChildren();
UISelectItem one = new UISelectItem();
one.setItemValue(new Integer(1));
children.add(one);
UISelectItem two = new UISelectItem();
two.setItemValue(new Integer(2));
children.add(two);
UISelectItem three = new UISelectItem();
three.setItemValue(new Integer(3));
children.add(three);
selectOne.validateValue(facesContext, 1);
Assert.assertTrue(selectOne.isValid());
Assert.assertEquals(0, facesContext.getMessageList().size());
}
Aggregations