Package org.apache.cocoon.forms.formmodel

Examples of org.apache.cocoon.forms.formmodel.Repeater$RepeaterRow


     * over to the actual binding-children.
     */
    public void doLoad(Widget frmModel, JXPathContext jxpc)
    throws BindingException {
        // Find the repeater
        Repeater repeater = (Repeater) selectWidget(frmModel, this.repeaterId);
        if (repeater == null) {
            throw new BindingException("The repeater with the ID [" + this.repeaterId
                    + "] referenced in the binding does not exist in the form definition.");
        }

        repeater.clear();

        Pointer ptr = jxpc.getPointer(this.repeaterPath);
        if (ptr.getNode() != null) {
            // There are some nodes to load from
            final int initialSize = repeater.getSize();

            // build a jxpath iterator for pointers
            JXPathContext repeaterContext = jxpc.getRelativeContext(ptr);
            Iterator rowPointers = repeaterContext.iteratePointers(this.rowPath);
            //iterate through it
            int currentRow = 0;
            while (rowPointers.hasNext()) {
                // create a new row, take that as the frmModelSubContext
                Repeater.RepeaterRow thisRow;
                if (currentRow < initialSize) {
                    thisRow = repeater.getRow(currentRow++);
                } else {
                    thisRow = repeater.addRow();
                }
                // make a jxpath ObjectModelSubcontext on the iterated element
                Pointer jxp = (Pointer)rowPointers.next();
                JXPathContext rowContext = repeaterContext.getRelativeContext(jxp);
                // hand it over to children
View Full Code Here


     * child-bindings are allowed to visit the narrowed contexts.
     */
    public void doSave(Widget frmModel, JXPathContext jxpc)
    throws BindingException {
        // Find the repeater
        Repeater repeater = (Repeater) selectWidget(frmModel, this.repeaterId);

        // and his context, creating the path if needed
        JXPathContext repeaterContext =
            jxpc.getRelativeContext(jxpc.createPath(this.repeaterPath));

        // create set of updatedRowIds
        Set updatedRows = new HashSet();
        //create list of rows to insert at end
        List rowsToInsert = new ArrayList();

        // iterate rows in the form model...
        int formRowCount = repeater.getSize();
        for (int i = 0; i < formRowCount; i++) {
            Repeater.RepeaterRow thisRow = repeater.getRow(i);

            // Get the identity
            List identity = getIdentity(thisRow);

            if (hasNonNullElements(identity)) {
View Full Code Here

        getWidget(widget, id).generateLabel(this.cocoonConsumer);
    }

    public void generateRepeaterWidgetLabel(Widget widget, String id, String widgetId) throws SAXException {
        // Widget labels are allowed either inside or outside of <ft:repeater>
        Repeater repeater = widget instanceof Repeater ? (Repeater)widget : getRepeater(widget, id);
        repeater.generateWidgetLabel(widgetId, this.cocoonConsumer);
    }
View Full Code Here

    public JXPathBindingBase[] getChildBindings() { return ((ComposedJXPathBindingBase)rowBinding).getChildBindings(); }

    public void doLoad(Widget frmModel, JXPathContext jctx)
            throws BindingException {
        // Find the repeater and clear it
        Repeater repeater = (Repeater) selectWidget(frmModel, this.repeaterId);

        if (this.clearOnLoad) {
            repeater.clear();
        }

        // Move to repeater context
        Pointer ptr = jctx.getPointer(this.repeaterPath);
        if (ptr.getNode() != null) {
            // There are some nodes to load from

            JXPathContext repeaterContext = jctx.getRelativeContext(ptr);
            // build a jxpath iterator for pointers
            Iterator rowPointers = repeaterContext.iteratePointers(this.rowPath);

            //iterate through it
            int rowNum = 0;
            while (rowPointers.hasNext()) {
                // Get a row. It is created if needed (depends on clearOnLoad)
                Repeater.RepeaterRow thisRow;
                if (repeater.getSize() > rowNum) {
                    thisRow = repeater.getRow(rowNum);
                } else {
                    thisRow = repeater.addRow();
                }
                rowNum++;

                // make a jxpath sub context on the iterated element
                Pointer jxp = (Pointer) rowPointers.next();
View Full Code Here

    }

    public void doSave(Widget frmModel, JXPathContext jctx)
            throws BindingException {
        // Find the repeater
        Repeater repeater = (Repeater)selectWidget(frmModel, this.repeaterId);

        if (repeater.getSize() == 0 && this.deleteIfEmpty) {
            // Repeater is empty : erase all
            jctx.removeAll(this.repeaterPath);
        } else {
            // Repeater is not empty
            // Move to repeater context and create the path if needed
            JXPathContext repeaterContext =
                jctx.getRelativeContext(jctx.createPath(this.repeaterPath));

            // Delete all that is already present
            repeaterContext.removeAll(this.rowPath);

            for (int i = 0; i < repeater.getSize(); i++) {
                Pointer rowPtr = repeaterContext.createPath(
                        this.rowPath + '[' + (i+1) + ']');
                JXPathContext rowContext =
                    repeaterContext.getRelativeContext(rowPtr);
                this.rowBinding.saveFormToModel(repeater.getRow(i),
                        rowContext);
            }
        }
    }
View Full Code Here

        getWidget(widget, id).generateLabel(this.cocoonConsumer);
    }

    public void generateRepeaterWidgetLabel(Widget widget, String id, String widgetId) throws SAXException {
        // Widget labels are allowed either inside or outside of <ft:repeater>
        Repeater repeater = widget instanceof Repeater ? (Repeater)widget : getRepeater(widget, id);
        repeater.generateWidgetLabel(widgetId, this.cocoonConsumer);
    }
View Full Code Here

     * Handles <code>ft:repeater-widget-label</code> element.
     */
    protected class RepeaterWidgetLabelHandler extends ErrorHandler {
        public Handler startElement(String uri, String loc, String raw, Attributes attrs)
        throws SAXException {
            Repeater repeater;
            if (contextWidget instanceof Repeater) {
                repeater = (Repeater)contextWidget;
            } else {
                setTypedWidget(loc, attrs, Repeater.class, "repeater");
                repeater = (Repeater)widget;
                widget = null;
            }
            String path = getRequiredAttributeValue(loc, attrs, "widget-id");
            repeater.generateWidgetLabel(path, getContentHandler());
            return this;
        }
View Full Code Here

        }

        public void endElement(String uri, String loc, String raw)
        throws SAXException {
            SaxBuffer buffer = endBuffer();
            final Repeater repeater = (Repeater) contextWidget;
            final int rowCount = repeater.getSize();
            pushHandler(hNested);
            contextWidgets.addFirst(contextWidget);
            for (int i = 0; i < rowCount; i++) {
                contextWidget = repeater.getRow(i);
                if (isVisible(contextWidget)) {
                    buffer.toSAX(EffectWidgetReplacingPipe.this);
                }
            }
            contextWidget = (Widget) contextWidgets.removeFirst();
View Full Code Here

        }

        public void endElement(String uri, String loc, String raw)
        throws SAXException {
            SaxBuffer buffer = endBuffer();
            final Repeater repeater = (Repeater) widget;
            final int rowCount = repeater.getSize();
            pushHandler(hNested);
            contextWidgets.addFirst(contextWidget);
            for (int i = 0; i < rowCount; i++) {
                contextWidget = repeater.getRow(i);
                if (isVisible(contextWidget)) {
                    buffer.toSAX(EffectWidgetReplacingPipe.this);
                }
            }
            contextWidget = (Widget) contextWidgets.removeFirst();
View Full Code Here

                                       " as child to: " + this.currentWidget.getId());
        } else if (this.currentWidget instanceof Repeater) {
            // In a repeater the XML elements are added in the order
            // they are recieved, the position attribute is not used
            if (ITEM.equals(loc)) {
                Repeater repeater = (Repeater)currentWidget;
                currentWidget = repeater.addRow();
            } else
                throw new SAXException("The element: " + loc +
                                       " is not allowed as a direct child of a Repeater");
        } else if (this.currentWidget instanceof MultiValueField) {
            this.isMultiValueItem = true;
View Full Code Here

TOP

Related Classes of org.apache.cocoon.forms.formmodel.Repeater$RepeaterRow

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.