Search in sources :

Example 6 with UISelectItems

use of javax.faces.component.UISelectItems in project acs-community-packaging by Alfresco.

the class UIMimeTypeSelector method encodeBegin.

@Override
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException {
    // SelectItems component.
    if (getChildren().size() == 0) {
        UISelectItems items = (UISelectItems) context.getApplication().createComponent("javax.faces.SelectItems");
        items.setId(this.getId() + "_items");
        items.setValue(createList());
        // add the child component
        getChildren().add(items);
    }
    // do the default processing
    super.encodeBegin(context);
}
Also used : UISelectItems(javax.faces.component.UISelectItems)

Example 7 with UISelectItems

use of javax.faces.component.UISelectItems in project acs-community-packaging by Alfresco.

the class TextFieldGenerator method createComponent.

@Override
@SuppressWarnings("unchecked")
protected UIComponent createComponent(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem item) {
    UIComponent component = null;
    if (propertySheet.inEditMode()) {
        // if the field has the list of values constraint
        // and it is editable a SelectOne component is
        // required otherwise create the standard edit component
        ListOfValuesConstraint constraint = getListOfValuesConstraint(context, propertySheet, item);
        PropertyDefinition propDef = this.getPropertyDefinition(context, propertySheet.getNode(), item.getName());
        if (constraint != null && item.isReadOnly() == false && propDef != null && propDef.isProtected() == false) {
            component = context.getApplication().createComponent(UISelectOne.COMPONENT_TYPE);
            FacesHelper.setupComponentId(context, component, item.getName());
            // create the list of choices
            UISelectItems itemsComponent = (UISelectItems) context.getApplication().createComponent("javax.faces.SelectItems");
            List<String> values = constraint.getAllowedValues();
            List<SelectItem> items = new ArrayList<SelectItem>(values.size());
            for (String value : values) {
                Object obj = null;
                // we need to setup the list with objects of the correct type
                if (propDef.getDataType().getName().equals(DataTypeDefinition.INT)) {
                    obj = Integer.valueOf(value);
                } else if (propDef.getDataType().getName().equals(DataTypeDefinition.LONG)) {
                    obj = Long.valueOf(value);
                } else if (propDef.getDataType().getName().equals(DataTypeDefinition.DOUBLE)) {
                    obj = Double.valueOf(value);
                } else if (propDef.getDataType().getName().equals(DataTypeDefinition.FLOAT)) {
                    obj = Float.valueOf(value);
                } else {
                    obj = value;
                }
                // retrieve the display label
                String label = constraint.getDisplayLabel(value, dataDictionary.getDictionaryService());
                if (label == null) {
                    label = value;
                }
                items.add(new SelectItem(obj, label));
            }
            itemsComponent.setValue(items);
            // add the items as a child component
            component.getChildren().add(itemsComponent);
        } else {
            // use the standard component in edit mode
            component = generate(context, item.getName());
        }
    } else {
        // create an output text component in view mode
        component = createOutputTextComponent(context, item.getName());
    }
    return component;
}
Also used : UISelectItems(javax.faces.component.UISelectItems) SelectItem(javax.faces.model.SelectItem) UIComponent(javax.faces.component.UIComponent) ArrayList(java.util.ArrayList) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Aggregations

UISelectItems (javax.faces.component.UISelectItems)7 UIComponent (javax.faces.component.UIComponent)3 ArrayList (java.util.ArrayList)2 SelectItem (javax.faces.model.SelectItem)2 ListOfValuesConstraint (org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint)2 List (java.util.List)1 UIInput (javax.faces.component.UIInput)1 UIOutput (javax.faces.component.UIOutput)1 UISelectBoolean (javax.faces.component.UISelectBoolean)1 UISelectOne (javax.faces.component.UISelectOne)1 ValueBinding (javax.faces.el.ValueBinding)1 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)1 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)1 QName (org.alfresco.service.namespace.QName)1