Search in sources :

Example 1 with UISelectMany

use of jakarta.faces.component.UISelectMany 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;
}
Also used : UISelectMany(jakarta.faces.component.UISelectMany) Set(java.util.Set) UISelectOne(jakarta.faces.component.UISelectOne)

Example 2 with UISelectMany

use of jakarta.faces.component.UISelectMany in project myfaces by apache.

the class _SharedRendererUtilsTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    uiSelectMany = new UISelectMany();
    submittedValue = new String[] { "1", "2" };
}
Also used : UISelectMany(jakarta.faces.component.UISelectMany)

Example 3 with UISelectMany

use of jakarta.faces.component.UISelectMany in project myfaces by apache.

the class UISelectManyTest method testValidateRequiredNull.

@Test
public void testValidateRequiredNull() {
    facesContext.getViewRoot().setLocale(_TEST_LOCALE);
    UISelectMany selectMany = new UISelectMany();
    selectMany.setId("selectMany");
    selectMany.setRendererType(null);
    selectMany.setRequired(true);
    List<UIComponent> children = selectMany.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);
    selectMany.validateValue(facesContext, null);
    Assert.assertFalse(selectMany.isValid());
}
Also used : UISelectMany(jakarta.faces.component.UISelectMany) UIComponent(jakarta.faces.component.UIComponent) Test(org.junit.Test)

Example 4 with UISelectMany

use of jakarta.faces.component.UISelectMany in project myfaces by apache.

the class UISelectManyTest method testValidateRequiredEmptyList.

@Test
public void testValidateRequiredEmptyList() {
    facesContext.getViewRoot().setLocale(_TEST_LOCALE);
    UISelectMany selectMany = new UISelectMany();
    selectMany.setId("selectMany");
    selectMany.setRendererType(null);
    selectMany.setRequired(true);
    List<UIComponent> children = selectMany.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);
    selectMany.validateValue(facesContext, Collections.EMPTY_LIST);
    Assert.assertFalse(selectMany.isValid());
}
Also used : UISelectMany(jakarta.faces.component.UISelectMany) UIComponent(jakarta.faces.component.UIComponent) Test(org.junit.Test)

Example 5 with UISelectMany

use of jakarta.faces.component.UISelectMany in project myfaces by apache.

the class HtmlCheckboxRendererBase method encodeEnd.

@Override
public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    if (uiComponent instanceof UISelectBoolean) {
        ResponseWriter writer = facesContext.getResponseWriter();
        writer.endElement(HTML.INPUT_ELEM);
    } else if (uiComponent instanceof UISelectMany) {
        renderCheckboxList(facesContext, (UISelectMany) uiComponent);
    } else {
        throw new IllegalArgumentException("Unsupported component class " + uiComponent.getClass().getName());
    }
}
Also used : UISelectMany(jakarta.faces.component.UISelectMany) ResponseWriter(jakarta.faces.context.ResponseWriter) UISelectBoolean(jakarta.faces.component.UISelectBoolean)

Aggregations

UISelectMany (jakarta.faces.component.UISelectMany)18 UISelectOne (jakarta.faces.component.UISelectOne)6 ResponseWriter (jakarta.faces.context.ResponseWriter)6 UIComponent (jakarta.faces.component.UIComponent)5 List (java.util.List)5 Test (org.junit.Test)5 UISelectBoolean (jakarta.faces.component.UISelectBoolean)4 ClientBehaviorHolder (jakarta.faces.component.behavior.ClientBehaviorHolder)4 Set (java.util.Set)4 PrintWriter (java.io.PrintWriter)2 BufferedResponseWrapper (com.sun.ts.tests.jsf.api.jakarta_faces.component.common.BufferedResponseWrapper)1 ExpressionFactory (jakarta.el.ExpressionFactory)1 ValueExpression (jakarta.el.ValueExpression)1 Converter (jakarta.faces.convert.Converter)1 SelectItem (jakarta.faces.model.SelectItem)1 SelectItemGroup (jakarta.faces.model.SelectItemGroup)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 SelectItemInfo (org.apache.myfaces.renderkit.html.util.SelectItemInfo)1