Search in sources :

Example 11 with ValueBinding

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;
}
Also used : ValueBinding(javax.faces.el.ValueBinding) UIInput(javax.faces.component.UIInput)

Example 12 with ValueBinding

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);
    }
}
Also used : ValueBinding(javax.faces.el.ValueBinding) DialogButtonConfig(org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig) MethodBinding(javax.faces.el.MethodBinding) UICommand(javax.faces.component.UICommand)

Example 13 with ValueBinding

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);
    }
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) ValueBinding(javax.faces.el.ValueBinding) ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) List(java.util.List) UIInput(javax.faces.component.UIInput)

Example 14 with ValueBinding

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;
}
Also used : ValueBinding(javax.faces.el.ValueBinding) EvaluationException(javax.faces.el.EvaluationException)

Example 15 with ValueBinding

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);
    }
}
Also used : ValueBinding(javax.faces.el.ValueBinding) UIListItems(org.alfresco.web.ui.common.component.UIListItems)

Aggregations

ValueBinding (javax.faces.el.ValueBinding)16 UIInput (javax.faces.component.UIInput)3 FacesContext (javax.faces.context.FacesContext)3 MethodBinding (javax.faces.el.MethodBinding)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 UICommand (javax.faces.component.UICommand)2 UIComponent (javax.faces.component.UIComponent)2 ResponseWriter (javax.faces.context.ResponseWriter)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 UIListItems (org.alfresco.web.ui.common.component.UIListItems)2 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 Iterator (java.util.Iterator)1 Application (javax.faces.application.Application)1 FacesMessage (javax.faces.application.FacesMessage)1 UIOutput (javax.faces.component.UIOutput)1 UISelectBoolean (javax.faces.component.UISelectBoolean)1 UISelectItems (javax.faces.component.UISelectItems)1