Package org.apache.cocoon.forms.formmodel

Examples of org.apache.cocoon.forms.formmodel.Widget


            getLogger().debug("done loading values " + this);
        }
    }

    public void doSave(Widget frmModel, JXPathContext jctx) throws BindingException {
        Widget widget = selectWidget(frmModel,this.multiValueId);
        Object[] values = (Object[])widget.getValue();

        JXPathContext multiValueContext = jctx.getRelativeContext(jctx.createPath(this.multiValuePath));

        // Delete all that is already present
View Full Code Here


    public Function getSaveScript() { return saveScript; }
    public Map getChildBindingsMap() { return childBindingsMap; }

    public void doLoad(Widget frmModel, JXPathContext jctx) {
        if (this.loadScript != null) {
            Widget widget = selectWidget(frmModel, this.id);

            // Move to widget context
            Pointer pointer = jctx.getPointer(this.path);

            Map objectModel = ContextHelper.getObjectModel(this.avalonContext);
View Full Code Here

        }
    }

    public void doSave(Widget frmModel, JXPathContext jctx) throws BindingException {
        if (this.saveScript != null) {
            Widget widget = selectWidget(frmModel, this.id);

            // Move to widget context and create the path if needed
            Pointer pointer = jctx.createPath(this.path);
            JXPathContext widgetCtx = jctx.getRelativeContext(pointer);
            try {
View Full Code Here

        /**
         * @see org.apache.cocoon.forms.validation.WidgetValidator#validate(org.apache.cocoon.forms.formmodel.Widget)
         */
        public void process(Widget form) {
            final Widget widget = form.lookupWidget(this.referenceId);
            if ( widget == null ) {
                throw new IllegalArgumentException("Widget '" + this.referenceId + "' not found in form.");
            }
            if (! (widget instanceof Field)) {
                // Invalid widget type
                throw new IllegalArgumentException("Widget '" + widget.getRequestParameterName() + "' is not a Field");
            }

            boolean required = false;
            if ( mode == DEPENDS_REQUIRED_MODE ) {
                final Widget w = form.lookupWidget(this.widgetName);
                if ( w != null ) {
                    if ( w.getValue() != null && w.getValue().equals(this.widgetValue)) {
                        required = true;
                    }
                }
            } else if ( mode == SUBMIT_REQUIRED_MODE ) {
                if ( widget.getForm().getSubmitWidget() != null) {
View Full Code Here

    /**
     * Actively performs the binding from the ObjectModel wrapped in a jxpath
     * context to the CForms-form-widget specified in this object.
     */
    public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException {
        Widget widget = selectWidget(frmModel, this.fieldId);
        if (widget == null) {
            throw new BindingException("The widget with the ID [" + this.fieldId
                    + "] referenced in the binding does not exist in the form definition.");
        }

        Object value = jxpc.getValue(this.xpath);
        if (value != null && convertor != null) {
            if (value instanceof String) {
                ConversionResult conversionResult = convertor.convertFromString((String)value, convertorLocale, null);
                if (conversionResult.isSuccessful())
                    value = conversionResult.getResult();
                else
                    value = null;
            } else {
                getLogger().warn("Convertor ignored on backend-value which isn't of type String.");
            }
        }

        widget.setValue(value);
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Done loading " + this + " -- value= " + value);
        }
    }
View Full Code Here

    /**
     * Actively performs the binding from the CForms-form to the ObjectModel
     * wrapped in a jxpath context
     */
    public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
        Widget widget = selectWidget(frmModel, this.fieldId);
        Object value = widget.getValue();
        if (value != null && convertor != null) {
            value = convertor.convertToString(value, convertorLocale, null);
        }

        Object oldValue = jxpc.getValue(this.xpath);
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("value= " + value + " -- oldvalue=" + oldValue);
        }

        boolean update = false;

        if ((value == null && oldValue != null) || value != null && !value.equals(oldValue)) {
            // first update the value itself
            jxpc.createPathAndSetValue(this.xpath, value);

            // now perform any other bindings that need to be performed when the value is updated
            JXPathContext subContext = null;
            try {
                subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
            } catch (JXPathException e) {
                // if the value has been set to null and the underlying model is a bean, then
                // JXPath will not be able to create a relative context
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("(Ignorable) problem binding field " + widget.getRequestParameterName(), e);
                }
            }
            if (subContext != null) {
                this.updateBinding.saveFormToModel(frmModel, subContext);
            }
View Full Code Here

     * @param path The path.
     */
    private void recurseRepeaters(Widget context, String path, boolean root) {
        String reppath = path.substring(0, path.indexOf('*') - 1);
        String childpath = path.substring(path.indexOf('*') + 2);
        Widget wdg = context.lookupWidget(reppath);
        if (wdg == null) {
            if (root) {
                throw new IllegalArgumentException("Cannot find a repeater with path " + reppath + " relative to widget " + context.getName());
            } else {
                return;
            }
        }
        if (!(wdg instanceof Repeater)) {
            throw new IllegalArgumentException("The widget with path " + reppath + " relative to widget " + context.getName() + " is not a repeater!");
        }
        Repeater repeater = (Repeater)wdg;
        if (context instanceof Repeater.RepeaterRow) {
            // Add this repeater to the repeater widgets
            addRepeaterWidget((Repeater) context.getParent(), repeater);
        }
       
        addRepeaterPath(repeater, childpath);
        if (childpath.indexOf('*') != -1) {
            for (int i = 0; i < repeater.getSize(); i++) {
                Repeater.RepeaterRow row = repeater.getRow(i);
                recurseRepeaters(row, childpath, false);
            }
        } else {
            for (int i = 0; i < repeater.getSize(); i++) {
                Repeater.RepeaterRow row = repeater.getRow(i);
              Widget okwdg = row.lookupWidget(childpath);
              if (okwdg != null) {
                  addRepeaterWidget(repeater, okwdg);
              }
            }
        }
View Full Code Here

        for (Iterator iter = paths.iterator(); iter.hasNext();) {
            String path = (String) iter.next();
            if (path.indexOf('*') != -1) {
                recurseRepeaters(row, path, false);
            } else {
                Widget wdg = row.lookupWidget(path);
                if (wdg == null) {
                    throw new IllegalStateException("Even after row addition cannot find a widget with path " + path + " in repeater " + repeater.getName());
                }
                addRepeaterWidget(repeater, wdg);
            }
View Full Code Here

     */
    protected void refreshForDelete(Repeater repeater, int index) {
        Repeater.RepeaterRow row = repeater.getRow(index);
        Set widgets = (Set) this.repeaterWidgets.get(repeater);
        for (Iterator iter = widgets.iterator(); iter.hasNext();) {
            Widget widget = (Widget) iter.next();
            boolean ischild = false;
            Widget parent = widget.getParent();
            while (parent != null) {
                if (parent == row) {
                    ischild = true;
                    break;
                }
                parent = parent.getParent();
            }
            if (ischild) {
                iter.remove();
                if (widget instanceof Repeater) {
                    if (this.repeaterPaths != null) this.repeaterPaths.remove(widget);
View Full Code Here

     * @param repeater The repeated that generated the event.
     */ 
    protected void refreshForClear(Repeater repeater) {
        Set widgets = (Set) this.repeaterWidgets.get(repeater);
        for (Iterator iter = widgets.iterator(); iter.hasNext();) {
            Widget widget = (Widget) iter.next();
            if (widget instanceof Repeater) {
                if (this.repeaterPaths != null) this.repeaterPaths.remove(widget);
                this.repeaterWidgets.remove(widget);
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.cocoon.forms.formmodel.Widget

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.