Search in sources :

Example 1 with UIComponent

use of javax.faces.component.UIComponent in project oxCore by GluuFederation.

the class UIInputContainer method assignIds.

// assigning ids seems to break form submissions, but I don't know why
public void assignIds(final InputContainerElements elements, final FacesContext context) {
    boolean refreshIds = false;
    if (getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) {
        setId(elements.getPropertyName(context));
        refreshIds = true;
    }
    UIComponent label = elements.getLabel();
    if (label != null) {
        if (label.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) {
            label.setId(getDefaultLabelId());
        } else if (refreshIds) {
            label.setId(label.getId());
        }
    }
    for (int i = 0, len = elements.getInputs().size(); i < len; i++) {
        UIComponent input = (UIComponent) elements.getInputs().get(i);
        if (input.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) {
            input.setId(getDefaultInputId() + (i == 0 ? "" : (i + 1)));
        } else if (refreshIds) {
            input.setId(input.getId());
        }
    }
    for (int i = 0, len = elements.getMessages().size(); i < len; i++) {
        UIComponent msg = elements.getMessages().get(i);
        if (msg.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) {
            msg.setId(getDefaultMessageId() + (i == 0 ? "" : (i + 1)));
        } else if (refreshIds) {
            msg.setId(msg.getId());
        }
    }
}
Also used : UIComponent(javax.faces.component.UIComponent)

Example 2 with UIComponent

use of javax.faces.component.UIComponent in project oxCore by GluuFederation.

the class EnumConverter method getAsObjectImpl.

public Object getAsObjectImpl(FacesContext context, UIComponent comp, String value) throws ConverterException {
    ValueExpression expr = comp.getValueExpression("value");
    Class enumType = expr == null ? null : expr.getType(context.getELContext());
    if (enumType != null && enumType.isEnum()) {
        return Enum.valueOf(enumType, value);
    } else {
        for (Object child : comp.getChildren()) {
            if (child instanceof UIComponent) {
                UIComponent c = (UIComponent) child;
                expr = c.getValueExpression("value");
                Object val = expr == null ? null : expr.getValue(context.getELContext());
                if (val == null) {
                    throw new ConverterException("Cannot get items");
                }
                Class t = val.getClass();
                if (t.isArray() && t.getComponentType().isEnum()) {
                    return Enum.valueOf(t.getComponentType(), value);
                } else if (val instanceof Collection) {
                    Object firstItem = ((Collection) val).iterator().next();
                    if (firstItem instanceof Enum) {
                        t = ((Enum) firstItem).getDeclaringClass();
                    } else {
                        t = firstItem.getClass();
                    }
                    return Enum.valueOf(t, value);
                }
            }
        }
    }
    throw new ConverterException("Unable to find selectItems with enum values.");
}
Also used : ConverterException(javax.faces.convert.ConverterException) ValueExpression(javax.el.ValueExpression) UIComponent(javax.faces.component.UIComponent) Collection(java.util.Collection)

Example 3 with UIComponent

use of javax.faces.component.UIComponent in project oxTrust by GluuFederation.

the class FacesComponentUtility method resetInputComponents.

private static void resetInputComponents(UIComponent rootUIComponent) {
    if ((rootUIComponent == null) || (rootUIComponent.getChildCount() == 0)) {
        return;
    }
    for (UIComponent comp : rootUIComponent.getChildren()) {
        if (comp instanceof UIInput) {
            UIInput uiInput = (UIInput) comp;
            uiInput.setSubmittedValue(null);
            uiInput.setValid(true);
            uiInput.setLocalValueSet(false);
            uiInput.resetValue();
        }
        resetInputComponents(comp);
    }
}
Also used : UIComponent(javax.faces.component.UIComponent) UIInput(javax.faces.component.UIInput)

Example 4 with UIComponent

use of javax.faces.component.UIComponent in project oxTrust by GluuFederation.

the class FacesComponentUtility method resetInputComponents.

public static void resetInputComponents(String rootCompId) {
    UIComponent rootUIComponent = findComponentById(rootCompId);
    resetInputComponents(rootUIComponent);
}
Also used : UIComponent(javax.faces.component.UIComponent)

Aggregations

UIComponent (javax.faces.component.UIComponent)4 Collection (java.util.Collection)1 ValueExpression (javax.el.ValueExpression)1 UIInput (javax.faces.component.UIInput)1 ConverterException (javax.faces.convert.ConverterException)1