use of javax.faces.el.ValueBinding in project acs-community-packaging by Alfresco.
the class UISearchCustomProperties method generateCheck.
/**
* Generates a JSF OutputText component/renderer
*
* @param context JSF context
* @param propDef PropertyDefinition
* @param beanBinding String
*
* @return UIComponent
*/
private UIComponent generateCheck(FacesContext context, PropertyDefinition propDef, String beanBinding) {
// enabled state checkbox
UIInput checkbox = (UIInput) context.getApplication().createComponent(ComponentConstants.JAVAX_FACES_SELECT_BOOLEAN);
checkbox.setRendererType(ComponentConstants.JAVAX_FACES_CHECKBOX);
checkbox.setId(context.getViewRoot().createUniqueId());
ValueBinding vbCheckbox = context.getApplication().createValueBinding("#{" + beanBinding + "[\"" + propDef.getName().toString() + "\"]}");
checkbox.setValueBinding(VALUE, vbCheckbox);
return checkbox;
}
use of javax.faces.el.ValueBinding in project acs-community-packaging by Alfresco.
the class UIDialogButtons method generateAdditionalButtons.
/**
* If there are any additional buttons to add as defined by the dialog
* configuration and the dialog at runtime they are generated in this
* method.
*
* @param context Faces context
*/
@SuppressWarnings("unchecked")
protected void generateAdditionalButtons(FacesContext context) {
// get potential list of additional buttons
List<DialogButtonConfig> buttons = Application.getDialogManager().getAdditionalButtons();
if (buttons != null && buttons.size() > 0) {
if (logger.isDebugEnabled())
logger.debug("Adding " + buttons.size() + " additional buttons: " + buttons);
// add a spacing row to separate the additional buttons from the OK button
addSpacingRow(context);
for (DialogButtonConfig buttonCfg : buttons) {
UICommand button = (UICommand) context.getApplication().createComponent(HtmlCommandButton.COMPONENT_TYPE);
button.setRendererType(ComponentConstants.JAVAX_FACES_BUTTON);
FacesHelper.setupComponentId(context, button, buttonCfg.getId());
// setup the value of the button (the label)
String label = buttonCfg.getLabel();
if (label != null) {
// see if the label represents a value binding
if (label.startsWith(BINDING_EXPRESSION_START)) {
ValueBinding binding = context.getApplication().createValueBinding(label);
button.setValueBinding("value", binding);
} else {
button.setValue(label);
}
} else {
// NOTE: the config checks that a label or a label id
// is present so we can assume there is an id
// if there isn't a label
String labelId = buttonCfg.getLabelId();
label = Application.getMessage(context, labelId);
button.setValue(label);
}
// setup the action binding, the config checks that an action
// is present so no need to check for NullPointer. It also checks
// it represents a method binding expression.
String action = buttonCfg.getAction();
MethodBinding methodBinding = context.getApplication().createMethodBinding(action, null);
button.setAction(methodBinding);
// setup the disabled attribute, check for null and
// binding expressions
String disabled = buttonCfg.getDisabled();
if (disabled != null && disabled.length() > 0) {
if (disabled.startsWith(BINDING_EXPRESSION_START)) {
ValueBinding binding = context.getApplication().createValueBinding(disabled);
button.setValueBinding("disabled", binding);
} else {
button.getAttributes().put("disabled", Boolean.parseBoolean(disabled));
}
}
// setup CSS class for the button
String styleClass = (String) this.getAttributes().get("styleClass");
if (styleClass != null) {
button.getAttributes().put("styleClass", styleClass);
}
// setup the onclick handler for the button
String onclick = buttonCfg.getOnclick();
if (onclick != null && onclick.length() > 0) {
button.getAttributes().put("onclick", onclick);
}
// add the button
this.getChildren().add(button);
if (logger.isDebugEnabled())
logger.debug("Added button with id of: " + button.getId());
}
// add a spacing row to separate the additional buttons from the Cancel button
addSpacingRow(context);
}
}
use of javax.faces.el.ValueBinding in project acs-community-packaging by Alfresco.
the class UIMultiValueEditor method broadcast.
/**
* @see javax.faces.component.UIComponent#broadcast(javax.faces.event.FacesEvent)
*/
public void broadcast(FacesEvent event) throws AbortProcessingException {
if (event instanceof MultiValueEditorEvent) {
MultiValueEditorEvent assocEvent = (MultiValueEditorEvent) event;
List items = (List) getValue();
switch(assocEvent.Action) {
case ACTION_SELECT:
{
this.addingNewItem = Boolean.TRUE;
break;
}
case ACTION_ADD:
{
if (items == null) {
items = new ArrayList();
setSubmittedValue(items);
}
Object addedItem = null;
if (getRendererType().equals(RepoConstants.ALFRESCO_FACES_FIELD_RENDERER)) {
UIInput childComponent = (UIInput) this.getChildren().get(0);
// as the 'field' is being submitted in the same request we can go
// directly to the submitted value to find the entered value
addedItem = childComponent.getSubmittedValue();
if (childComponent.getRendererType() != null && childComponent.getRendererType().equals(RepoConstants.ALFRESCO_FACES_DATE_PICKER_RENDERER)) {
// the submitted value for the date is in it's raw form, convert to date
int[] parts = (int[]) addedItem;
Calendar date = new GregorianCalendar(parts[0], parts[1], parts[2], parts[3], parts[4]);
addedItem = date.getTime();
}
// conversely, we can erase the submitted value
childComponent.setSubmittedValue(null);
} else {
addedItem = getLastItemAdded();
this.addingNewItem = Boolean.FALSE;
// get hold of the value binding for the lastItemAdded property
// and set it to null to show it's been added to the list
ValueBinding vb = getValueBinding("lastItemAdded");
if (vb != null) {
vb.setValue(FacesContext.getCurrentInstance(), null);
}
}
if (addedItem != null) {
items.add(addedItem);
}
break;
}
case ACTION_REMOVE:
{
items.remove(assocEvent.RemoveIndex);
break;
}
}
} else {
super.broadcast(event);
}
}
use of javax.faces.el.ValueBinding in project acs-community-packaging by Alfresco.
the class FacesHelper method getManagedBean.
/**
* Return a JSF managed bean reference.
*
* @param fc FacesContext
* @param name Name of the managed bean to return
*
* @return the managed bean or null if not found
*/
public static Object getManagedBean(FacesContext fc, String name) {
Object obj = null;
try {
ValueBinding vb = fc.getApplication().createValueBinding("#{" + name + "}");
obj = vb.getValue(fc);
} catch (EvaluationException ee) {
// not much we can do here, just make sure return is null
if (logger.isDebugEnabled())
logger.debug("Failed to resolve managed bean: " + name, ee);
obj = null;
}
return obj;
}
use of javax.faces.el.ValueBinding in project acs-community-packaging by Alfresco.
the class SpaceIconPickerGenerator method setupProperty.
@Override
@SuppressWarnings("unchecked")
protected void setupProperty(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem item, PropertyDefinition propertyDef, UIComponent component) {
// do the standard setup
super.setupProperty(context, propertySheet, item, propertyDef, component);
// list of icons the user can select from
if (propertySheet.inEditMode()) {
// create the list items child component
UIListItems items = (UIListItems) context.getApplication().createComponent(RepoConstants.ALFRESCO_FACES_LIST_ITEMS);
// setup the value binding for the list of icons, this needs
// to be sensitive to the bean used for the property sheet
// we therefore need to get the value binding expression and
// extract the bean name and then add '.icons' to the end,
// this means any page that uses this component must supply
// a getIcons method that returns a List of UIListItem's
ValueBinding binding = propertySheet.getValueBinding("value");
String expression = binding.getExpressionString();
String beanName = expression.substring(2, expression.indexOf(".") + 1);
if (beanName.equals("DialogManager.") || beanName.equals("WizardManager.")) {
// deal with the special dialog and wizard manager beans by
// adding .bean
beanName = beanName + "bean.";
}
String newExpression = "#{" + beanName + "icons}";
ValueBinding vb = context.getApplication().createValueBinding(newExpression);
items.setValueBinding("value", vb);
// add the list items component to the image picker component
component.getChildren().add(items);
}
}
Aggregations