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);
}
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;
}
Aggregations