Search in sources :

Example 1 with ValueBinding

use of javax.faces.el.ValueBinding in project acs-community-packaging by Alfresco.

the class GetCommand method execute.

public void execute(FacesContext facesContext, String expression, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // create the JSF binding expression
    String bindingExpr = makeBindingExpression(expression);
    if (logger.isDebugEnabled())
        logger.debug("Retrieving value from value binding: " + bindingExpr);
    UserTransaction tx = null;
    try {
        // create the value binding
        ValueBinding binding = facesContext.getApplication().createValueBinding(bindingExpr);
        if (binding != null) {
            // setup the transaction
            tx = Repository.getUserTransaction(facesContext, true);
            tx.begin();
            // get the value from the value binding
            Object value = binding.getValue(facesContext);
            if (value != null) {
                response.getWriter().write(value.toString());
            }
            // commit
            tx.commit();
        }
    } catch (Throwable err) {
        // rollback the transaction
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
        }
        throw new AlfrescoRuntimeException("Failed to retrieve value: " + err.getMessage(), err);
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) ValueBinding(javax.faces.el.ValueBinding) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 2 with ValueBinding

use of javax.faces.el.ValueBinding in project acs-community-packaging by Alfresco.

the class UISearchCustomProperties method generateControl.

/**
 * Generates an appropriate control for the given property
 *
 * @param context       JSF context
 * @param propDef       The definition of the property to create the control for
 * @param displayLabel  Display label for the component
 * @param beanBinding   Combined name of the value bound bean and variable used for value binding expression
 *
 * @return UIComponent
 */
@SuppressWarnings("unchecked")
private UIComponent generateControl(FacesContext context, PropertyDefinition propDef, String displayLabel, String beanBinding) {
    UIComponent control = null;
    DataTypeDefinition dataTypeDef = propDef.getDataType();
    QName typeName = dataTypeDef.getName();
    javax.faces.application.Application facesApp = context.getApplication();
    // create default value binding to a Map of values with a defined name
    ValueBinding vb = facesApp.createValueBinding("#{" + beanBinding + "[\"" + propDef.getName().toString() + "\"]}");
    // generate the appropriate input field
    if (typeName.equals(DataTypeDefinition.BOOLEAN)) {
        control = (UISelectBoolean) facesApp.createComponent(ComponentConstants.JAVAX_FACES_SELECT_BOOLEAN);
        control.setRendererType(ComponentConstants.JAVAX_FACES_CHECKBOX);
        control.setValueBinding(VALUE, vb);
    } else if (typeName.equals(DataTypeDefinition.CATEGORY)) {
        control = (UICategorySelector) facesApp.createComponent(RepoConstants.ALFRESCO_FACES_TAG_SELECTOR);
        control.setValueBinding(VALUE, vb);
    } else if (typeName.equals(DataTypeDefinition.DATETIME) || typeName.equals(DataTypeDefinition.DATE)) {
        Boolean showTime = Boolean.valueOf(typeName.equals(DataTypeDefinition.DATETIME));
        // create value bindings for the start year and year count attributes
        ValueBinding startYearBind = null;
        ValueBinding yearCountBind = null;
        if (showTime) {
            startYearBind = facesApp.createValueBinding("#{DateTimePickerGenerator.startYear}");
            yearCountBind = facesApp.createValueBinding("#{DateTimePickerGenerator.yearCount}");
        } else {
            startYearBind = facesApp.createValueBinding("#{DatePickerGenerator.startYear}");
            yearCountBind = facesApp.createValueBinding("#{DatePickerGenerator.yearCount}");
        }
        // Need to output component for From and To date selectors and labels
        // also neeed checkbox for enable/disable state - requires an outer wrapper component
        control = (UIPanel) facesApp.createComponent(ComponentConstants.JAVAX_FACES_PANEL);
        control.setRendererType(ComponentConstants.JAVAX_FACES_GRID);
        control.getAttributes().put("columns", Integer.valueOf(2));
        // enabled state checkbox
        UIInput checkbox = (UIInput) facesApp.createComponent(ComponentConstants.JAVAX_FACES_SELECT_BOOLEAN);
        checkbox.setRendererType(ComponentConstants.JAVAX_FACES_CHECKBOX);
        checkbox.setId(context.getViewRoot().createUniqueId());
        ValueBinding vbCheckbox = facesApp.createValueBinding("#{" + beanBinding + "[\"" + propDef.getName().toString() + "\"]}");
        checkbox.setValueBinding(VALUE, vbCheckbox);
        control.getChildren().add(checkbox);
        // main display label
        UIOutput label = (UIOutput) context.getApplication().createComponent(ComponentConstants.JAVAX_FACES_OUTPUT);
        label.setId(context.getViewRoot().createUniqueId());
        label.setRendererType(ComponentConstants.JAVAX_FACES_TEXT);
        label.setValue(displayLabel + ":");
        control.getChildren().add(label);
        // from date label
        UIOutput labelFromDate = (UIOutput) context.getApplication().createComponent(ComponentConstants.JAVAX_FACES_OUTPUT);
        labelFromDate.setId(context.getViewRoot().createUniqueId());
        labelFromDate.setRendererType(ComponentConstants.JAVAX_FACES_TEXT);
        labelFromDate.setValue(Application.getMessage(context, MSG_FROM));
        control.getChildren().add(labelFromDate);
        // from date control
        UIInput inputFromDate = (UIInput) facesApp.createComponent(ComponentConstants.JAVAX_FACES_INPUT);
        inputFromDate.setId(context.getViewRoot().createUniqueId());
        inputFromDate.setRendererType(RepoConstants.ALFRESCO_FACES_DATE_PICKER_RENDERER);
        inputFromDate.setValueBinding("startYear", startYearBind);
        inputFromDate.setValueBinding("yearCount", yearCountBind);
        inputFromDate.getAttributes().put("initialiseIfNull", Boolean.TRUE);
        inputFromDate.getAttributes().put("showTime", showTime);
        ValueBinding vbFromDate = facesApp.createValueBinding("#{" + beanBinding + "[\"" + PREFIX_DATE_FROM + propDef.getName().toString() + "\"]}");
        inputFromDate.setValueBinding(VALUE, vbFromDate);
        control.getChildren().add(inputFromDate);
        // to date label
        UIOutput labelToDate = (UIOutput) context.getApplication().createComponent(ComponentConstants.JAVAX_FACES_OUTPUT);
        labelToDate.setId(context.getViewRoot().createUniqueId());
        labelToDate.setRendererType(ComponentConstants.JAVAX_FACES_TEXT);
        labelToDate.setValue(Application.getMessage(context, MSG_TO));
        control.getChildren().add(labelToDate);
        // to date control
        UIInput inputToDate = (UIInput) facesApp.createComponent(ComponentConstants.JAVAX_FACES_INPUT);
        inputToDate.setId(context.getViewRoot().createUniqueId());
        inputToDate.setRendererType(RepoConstants.ALFRESCO_FACES_DATE_PICKER_RENDERER);
        inputToDate.setValueBinding("startYear", startYearBind);
        inputToDate.setValueBinding("yearCount", yearCountBind);
        inputToDate.getAttributes().put("initialiseIfNull", Boolean.TRUE);
        inputToDate.getAttributes().put("showTime", showTime);
        ValueBinding vbToDate = facesApp.createValueBinding("#{" + beanBinding + "[\"" + PREFIX_DATE_TO + propDef.getName().toString() + "\"]}");
        inputToDate.setValueBinding(VALUE, vbToDate);
        control.getChildren().add(inputToDate);
    } else if (typeName.equals(DataTypeDefinition.NODE_REF)) {
        control = (UISpaceSelector) facesApp.createComponent(RepoConstants.ALFRESCO_FACES_SPACE_SELECTOR);
        control.setValueBinding(VALUE, vb);
    } else {
        ListOfValuesConstraint constraint = getListOfValuesConstraint(propDef);
        if (constraint != null && propDef != null && propDef.isProtected() == false) {
            control = (UISelectOne) facesApp.createComponent(UISelectOne.COMPONENT_TYPE);
            UISelectItems itemsComponent = (UISelectItems) facesApp.createComponent(ComponentConstants.JAVAX_FACES_SELECT_ITEMS);
            List<SelectItem> items = new ArrayList<SelectItem>();
            List<String> values = constraint.getAllowedValues();
            for (String value : values) {
                items.add(new SelectItem(value, value));
            }
            itemsComponent.setValue(items);
            // add the items as a child component
            control.getChildren().add(itemsComponent);
            ValueBinding vbItemList = facesApp.createValueBinding("#{" + beanBinding + "[\"" + PREFIX_LOV_ITEM + propDef.getName().toString() + "\"]}");
            control.setValueBinding(VALUE, vbItemList);
        } else {
            // any other type is represented as an input text field
            control = (UIInput) facesApp.createComponent(ComponentConstants.JAVAX_FACES_INPUT);
            control.setRendererType(ComponentConstants.JAVAX_FACES_TEXT);
            control.setValueBinding("size", facesApp.createValueBinding("#{TextFieldGenerator.size}"));
            control.setValueBinding("maxlength", facesApp.createValueBinding("#{TextFieldGenerator.maxLength}"));
            control.setValueBinding(VALUE, vb);
        }
    }
    // set up the common aspects of the control
    control.setId(context.getViewRoot().createUniqueId());
    return control;
}
Also used : UISelectItems(javax.faces.component.UISelectItems) QName(org.alfresco.service.namespace.QName) ValueBinding(javax.faces.el.ValueBinding) UIComponent(javax.faces.component.UIComponent) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) UIInput(javax.faces.component.UIInput) UIOutput(javax.faces.component.UIOutput) SelectItem(javax.faces.model.SelectItem) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint) ArrayList(java.util.ArrayList) List(java.util.List) UISelectBoolean(javax.faces.component.UISelectBoolean) UISelectOne(javax.faces.component.UISelectOne)

Example 3 with ValueBinding

use of javax.faces.el.ValueBinding in project acs-community-packaging by Alfresco.

the class UISidebar method encodeBegin.

@SuppressWarnings("unchecked")
@Override
public void encodeBegin(FacesContext context) throws IOException {
    if (!isRendered())
        return;
    ResponseWriter out = context.getResponseWriter();
    out.write("<div id='sidebar' class='sidebar'>");
    // render the start of the header panel
    String cxPath = context.getExternalContext().getRequestContextPath();
    out.write("<table cellspacing='0' cellpadding='0' style='background-color: #ffffff;' width='100%'>" + "<tr valign='top'><td width='20%'><table cellspacing='0' cellpadding='0' width='100%'>" + "<tr><td style='width: 5px; background-image: url(");
    out.write(cxPath);
    out.write("/images/parts/sidebar_top_grey_begin.gif)' valign='top'>" + "<img src=\"");
    out.write(cxPath);
    out.write("/images/parts/sidebar_grey_01.gif\" width='5' height='5' alt=''></td>" + "<td style='height: 24px; background-image: url(");
    out.write(cxPath);
    out.write("/images/parts/sidebar_top_grey_bg.gif)'>");
    // generate the required child components if not present
    if (this.getChildCount() == 1) {
        // create the mode list component
        UIModeList modeList = (UIModeList) context.getApplication().createComponent("org.alfresco.faces.ModeList");
        modeList.setId("sidebarPluginList");
        modeList.setValue(this.getActivePlugin());
        modeList.setIconColumnWidth(2);
        modeList.setMenu(true);
        modeList.setMenuImage("/images/icons/menu.gif");
        modeList.getAttributes().put("itemSpacing", 4);
        modeList.getAttributes().put("styleClass", "moreActionsMenu");
        modeList.getAttributes().put("selectedStyleClass", "statusListHighlight");
        MethodBinding listener = context.getApplication().createMethodBinding("#{SidebarBean.pluginChanged}", new Class[] { ActionEvent.class });
        modeList.setActionListener(listener);
        // create the child list items component
        UIListItems items = (UIListItems) context.getApplication().createComponent("org.alfresco.faces.ListItems");
        ValueBinding binding = context.getApplication().createValueBinding("#{SidebarBean.plugins}");
        items.setValueBinding("value", binding);
        // add the list items to the mode list component
        modeList.getChildren().add(items);
        // create the actions component
        UIActions actions = (UIActions) context.getApplication().createComponent("org.alfresco.faces.Actions");
        actions.setId("sidebarActions");
        actions.setShowLink(false);
        setupActionGroupId(context, actions);
        // add components to the sidebar
        this.getChildren().add(0, modeList);
        this.getChildren().add(1, actions);
    } else {
        // update the child UIActions component with the correct
        // action group id and clear it's current children
        UIActions actions = (UIActions) this.getChildren().get(1);
        actions.reset();
        setupActionGroupId(context, actions);
    }
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) ValueBinding(javax.faces.el.ValueBinding) UIListItems(org.alfresco.web.ui.common.component.UIListItems) UIModeList(org.alfresco.web.ui.common.component.UIModeList) MethodBinding(javax.faces.el.MethodBinding)

Example 4 with ValueBinding

use of javax.faces.el.ValueBinding in project acs-community-packaging by Alfresco.

the class UIDialogButtons method generateButtons.

/**
 * Generates the buttons for the dialog currently being shown.
 *
 * @param context Faces context
 */
@SuppressWarnings("unchecked")
protected void generateButtons(FacesContext context) {
    // generate the OK button, if necessary
    if (Application.getDialogManager().isOKButtonVisible()) {
        UICommand okButton = (UICommand) context.getApplication().createComponent(HtmlCommandButton.COMPONENT_TYPE);
        okButton.setRendererType(ComponentConstants.JAVAX_FACES_BUTTON);
        FacesHelper.setupComponentId(context, okButton, "finish-button");
        // create the binding for the finish button label
        ValueBinding valueBinding = context.getApplication().createValueBinding("#{DialogManager.finishButtonLabel}");
        okButton.setValueBinding("value", valueBinding);
        // create the action binding
        MethodBinding methodBinding = context.getApplication().createMethodBinding("#{DialogManager.finish}", null);
        okButton.setAction(methodBinding);
        // create the binding for whether the button is disabled
        valueBinding = context.getApplication().createValueBinding("#{DialogManager.finishButtonDisabled}");
        okButton.setValueBinding("disabled", valueBinding);
        // setup CSS class for button
        String styleClass = (String) this.getAttributes().get("styleClass");
        if (styleClass != null) {
            okButton.getAttributes().put("styleClass", styleClass);
        }
        // add the OK button
        this.getChildren().add(okButton);
    }
    // generate the additional buttons
    generateAdditionalButtons(context);
    // generate the OK button
    UICommand cancelButton = (UICommand) context.getApplication().createComponent(HtmlCommandButton.COMPONENT_TYPE);
    cancelButton.setRendererType(ComponentConstants.JAVAX_FACES_BUTTON);
    FacesHelper.setupComponentId(context, cancelButton, "cancel-button");
    // create the binding for the cancel button label
    ValueBinding valueBinding = context.getApplication().createValueBinding("#{DialogManager.cancelButtonLabel}");
    cancelButton.setValueBinding("value", valueBinding);
    // create the action binding
    MethodBinding methodBinding = context.getApplication().createMethodBinding("#{DialogManager.cancel}", null);
    cancelButton.setAction(methodBinding);
    // setup CSS class for button
    String styleClass = (String) this.getAttributes().get("styleClass");
    if (styleClass != null) {
        cancelButton.getAttributes().put("styleClass", styleClass);
    }
    // set the immediate flag to true
    cancelButton.getAttributes().put("immediate", Boolean.TRUE);
    // add the Cancel button
    this.getChildren().add(cancelButton);
}
Also used : ValueBinding(javax.faces.el.ValueBinding) MethodBinding(javax.faces.el.MethodBinding) UICommand(javax.faces.component.UICommand)

Example 5 with ValueBinding

use of javax.faces.el.ValueBinding in project acs-community-packaging by Alfresco.

the class ErrorsRenderer method encodeBegin.

/**
 * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
 */
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
    if (component.isRendered() == false) {
        return;
    }
    Iterator messages = context.getMessages();
    if (messages.hasNext()) {
        ResponseWriter out = context.getResponseWriter();
        String contextPath = context.getExternalContext().getRequestContextPath();
        String styleClass = (String) component.getAttributes().get("styleClass");
        String errorClass = (String) component.getAttributes().get("errorClass");
        if (errorClass == null) {
            errorClass = DEFAULT_CSS_ERROR;
        }
        String infoClass = (String) component.getAttributes().get("infoClass");
        if (infoClass == null) {
            infoClass = DEFAULT_CSS_INFO;
        }
        String message = (String) component.getAttributes().get("message");
        String errorHint = Application.getMessage(context, ERROR_HINT);
        if (message == null) {
            // because we are using the standard messages component value binding
            // would not be handled for the message attribute so do it here
            ValueBinding vb = component.getValueBinding("message");
            if (vb != null) {
                message = (String) vb.getValue(context);
            }
            if (message == null) {
                message = Application.getMessage(context, DEFAULT_MESSAGE);
            }
        }
        PanelGenerator.generatePanelStart(out, contextPath, "yellowInner", "#ffffcc");
        out.write("\n<div");
        if (styleClass != null) {
            outputAttribute(out, styleClass, "class");
        }
        out.write(">");
        // if we have a message to display show it next to the info icon
        if (message.length() > 0 && context.getMaximumSeverity().compareTo(FacesMessage.SEVERITY_WARN) > 0) {
            out.write("<img src='");
            out.write(contextPath);
            out.write("/images/icons/info_icon.gif' alt='");
            out.write(Utils.encode(errorHint));
            out.write("' align='absmiddle'/>&nbsp;&nbsp;");
            out.write(Utils.encode(message));
            out.write("\n<ul style='margin:2px;'>");
            while (messages.hasNext()) {
                FacesMessage fm = (FacesMessage) messages.next();
                out.write("<li");
                renderMessageAttrs(fm, out, errorClass, infoClass);
                out.write(">");
                out.write(Utils.encode(fm.getDetail()));
                out.write("</li>\n");
            }
            out.write("</ul>");
        } else {
            // if there is no title message to display use a table to place
            // the info icon on the left and the list of messages on the right
            out.write("<table border='0' cellpadding='3' cellspacing='0'><tr><td valign='top'><img src='");
            out.write(contextPath);
            out.write("/images/icons/info_icon.gif' alt='");
            out.write(Utils.encode(errorHint));
            out.write("'/>");
            out.write("</td><td>");
            while (messages.hasNext()) {
                FacesMessage fm = (FacesMessage) messages.next();
                out.write("<div style='margin-bottom: 3px;'");
                renderMessageAttrs(fm, out, errorClass, infoClass);
                out.write(">");
                out.write(Utils.encode(fm.getDetail()));
                out.write("</div>\n");
            }
            out.write("</td></tr></table>");
        }
        out.write("</div>\n");
        PanelGenerator.generatePanelEnd(out, contextPath, "yellowInner");
        // TODO: Expose this as a configurable attribute i.e. padding at bottom
        out.write("<div style='padding:2px;'></div>");
    }
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) ValueBinding(javax.faces.el.ValueBinding) Iterator(java.util.Iterator) FacesMessage(javax.faces.application.FacesMessage)

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