Package org.apache.cocoon.woody.formmodel

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


     * objectModelContext and Repeater to the repeated rows before handing
     * over to the actual binding-children.
     */
    public void loadFormFromModel(Widget frmModel, JXPathContext jxpc) {
        // Find the repeater
        Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId);

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

        //iterate through it
        while (rowPointers.hasNext()) {
            // create a new row, take that as the frmModelSubContext
            Repeater.RepeaterRow thisRow = repeater.addRow();

            // make a jxpath ObjectModelSubcontext on the iterated element
            Pointer jxp = (Pointer) rowPointers.next();
            JXPathContext rowContext = repeaterContext.getRelativeContext(jxp);

View Full Code Here


     * updated, inserted or removed.  Depending on what happened the appropriate
     * child-bindings are alowed to visit the narrowed contexts.
     */
    public void saveFormToModel(Widget frmModel, JXPathContext jxpc) throws BindingException {
        // Find the repeater
        Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId);

        // and his context
        JXPathContext repeaterContext =
            jxpc.getRelativeContext(jxpc.getPointer(this.repeaterPath));

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

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

            //TODO future might need data-conversion here
            Widget rowIdWidget = thisRow.getWidget(this.uniqueRowId);
            String rowIdValue = (String) rowIdWidget.getValue();

View Full Code Here

        if (inWidgetElement) {
            if (elementNestingCounter == widgetElementNesting && Constants.WT_NS.equals(namespaceURI)
                && (localName.equals(WIDGET) || localName.equals(REPEATER_WIDGET))) {
                    if (repeaterWidget) {
                        Repeater repeater = (Repeater)widget;
                        WidgetReplacingPipe rowPipe = new WidgetReplacingPipe();
                        int rowCount = repeater.getSize();
                        for (int i = 0; i < rowCount; i++) {
                            Repeater.RepeaterRow row = repeater.getRow(i);
                            rowPipe.init(row, pipeContext);
                            rowPipe.setContentHandler(contentHandler);
                            rowPipe.setLexicalHandler(lexicalHandler);
                            saxBuffer.toSAX(rowPipe);
                            rowPipe.recycle();
View Full Code Here

                out.bufferInit();
                return this;
            case EVENT_ELEMENT:
                return bufferHandler;
            case EVENT_END_ELEMENT:
                Repeater repeater = (Repeater)widget;
                int rowCount = repeater.getSize();
                handlers.addFirst(handler);
                handler = nestedHandler;
                contextWidgets.addFirst(contextWidget);
                for (int i = 0; i < rowCount; i++) {
                    Repeater.RepeaterRow row = repeater.getRow(i);
                    contextWidget = row;
                    out.getBuffer().toSAX(EffectWidgetReplacingPipe.this);
                }
                contextWidget = (Widget)contextWidgets.removeFirst();
                handler = (Handler)handlers.removeFirst();
View Full Code Here

        if (inWidgetElement) {
            if (elementNestingCounter == widgetElementNesting && Constants.WT_NS.equals(namespaceURI)
                && (localName.equals(WIDGET) || localName.equals(REPEATER_WIDGET))) {
                    if (repeaterWidget) {
                        Repeater repeater = (Repeater)widget;
                        WidgetReplacingPipe rowPipe = new WidgetReplacingPipe();
                        int rowCount = repeater.getSize();
                        for (int i = 0; i < rowCount; i++) {
                            Repeater.RepeaterRow row = repeater.getRow(i);
                            rowPipe.init(row, pipeContext);
                            rowPipe.setContentHandler(contentHandler);
                            rowPipe.setLexicalHandler(lexicalHandler);
                            saxBuffer.toSAX(rowPipe);
                            rowPipe.recycle();
View Full Code Here

                out.bufferInit();
                return this;
            case EVENT_ELEMENT:
                return bufferHandler;
            case EVENT_END_ELEMENT:
                Repeater repeater = (Repeater)widget;
                int rowCount = repeater.getSize();
                handlers.addFirst(handler);
                handler = nestedHandler;
                contextWidgets.addFirst(contextWidget);
                for (int i = 0; i < rowCount; i++) {
                    Repeater.RepeaterRow row = repeater.getRow(i);
                    contextWidget = row;
                    out.getBuffer().toSAX(EffectWidgetReplacingPipe.this);
                }
                contextWidget = (Widget)contextWidgets.removeFirst();
                handler = (Handler)handlers.removeFirst();
View Full Code Here

        Form form = formManager.createForm(resolver.resolveURI(formSource));

        Field birthDate = (Field)form.getWidget("birthdate");
        birthDate.setValue(new Date());

        Repeater repeater = (Repeater)form.getWidget("contacts");
        repeater.addRow();
        Field field = (Field)repeater.getWidget(0, "firstname");
        field.setValue("Jules");

        repeater.addRow();
        field = (Field)repeater.getWidget(1, "firstname");
        field.setValue("Lucien");

        Request request = ObjectModelHelper.getRequest(objectModel);
        request.setAttribute(formAttribute, form);
View Full Code Here

    public void doLoad(Widget frmModel, JXPathContext jctx) throws BindingException {
        // (There should be a general widget type checker for all the bindings to use,
        // coupled with a general informative exception class to throw if the widget is
        // of the wrong type or null.)
        Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId);
        if (repeater == null) {
            String fullId = frmModel.getFullyQualifiedId();
            if (fullId == null || fullId.length() == 0) {
                fullId = "";
            } else {
                fullId = fullId + ".";
            }
            throw new RuntimeException(
                "TempRepeaterJXPathBinding: Repeater \"" + fullId + this.repeaterId +
                "\" does not exist (" + frmModel.getLocation() + ")");
        }
        // Start by clearing the repeater, if necessary.
        if (this.clearOnLoad) {
            repeater.removeRows();
        }

        // Find the location of the repeater data.
        Pointer repeaterPointer = jctx.getPointer(this.repeaterPath);

        // Check if there is data present.
        //
        // (Otherwise, should we check the leniency config option
        // to decide whether to be silent or throw an exception?)
        if (repeaterPointer != null) {

            // Narrow to repeater context.
            JXPathContext repeaterContext = jctx.getRelativeContext(repeaterPointer);

            // Build a jxpath iterator for the repeater row pointers.
            Iterator rowPointers = repeaterContext.iteratePointers(this.rowPath);

            // Iterate through the rows of data.
            int rowNum = 0;
            while (rowPointers.hasNext()) {

                // Get or create a row widget.
                Repeater.RepeaterRow thisRow;
                if (repeater.getSize() > rowNum) {
                    thisRow = repeater.getRow(rowNum);
                } else {
                    thisRow = repeater.addRow();
                }
                rowNum++;

                // Narrow to the row context.
                Pointer rowPointer = (Pointer) rowPointers.next();
View Full Code Here

            getLogger().debug("done loading rows " + toString());
    }

    public void doSave(Widget frmModel, JXPathContext jctx) throws BindingException {
        // (See comment in doLoad about type checking and throwing a meaningful exception.)
        Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId);

        // Perform shortcut binding if the repeater is empty
        // and the deleteIfEmpty config option is selected.
        if (repeater.getSize() == 0 && this.deleteIfEmpty) {
            // Delete all of the old data for this repeater.
            jctx.removeAll(this.repeaterPath);

        // Otherwise perform the normal save binding.
        } else {

            // Narrow to the repeater context, creating the path if it did not exist.
            JXPathContext repeaterContext = jctx.getRelativeContext(jctx.createPath(this.repeaterPath));

            // Start by deleting all of the old row data.
            repeaterContext.removeAll(this.rowPath);

            // Verify that repeater is not empty and has an insert row binding.
            if(repeater.getSize() > 0) {
                if (this.insertRowBinding != null) {

                    //register the factory!
                    //this.insertRowBinding.saveFormToModel(repeater, repeaterContext);

                    // Iterate through the repeater rows.
                    for (int i = 0; i < repeater.getSize(); i++) {

                        // Narrow to the repeater row context.
                        Pointer rowPointer = repeaterContext.getPointer(this.rowPathInsert);
                        JXPathContext rowContext = repeaterContext.getRelativeContext(rowPointer);

                        // Variables used for virtual rows.
                        // They are initialized here just to keep the compiler happy.
                        Node rowNode = null;
                        Node virtualNode = null;

                        // If virtual rows are requested, create a temporary node and
                        // narrow the context to this initially empty new virtual row.
                        if (virtualRows == true) {
                            rowNode = (Node)rowContext.getContextBean();
                            virtualNode = rowNode.getOwnerDocument().createElementNS(null, "virtual");
                            rowContext = JXPathContext.newContext(repeaterContext, virtualNode);
                        }

                        // Perform the insert row binding
                        this.insertRowBinding.saveFormToModel(repeater, rowContext);

                        // Perform the save row binding.
                        this.rowBinding.saveFormToModel(repeater.getRow(i), rowContext);

                        // If virtual rows are requested, finish by appending the
                        // children of the virtual row to the real context node.
                        if (virtualRows == true) {
                            NodeList list = virtualNode.getChildNodes();
View Full Code Here

    public boolean has(int index, Scriptable start) {
        if (super.has(index, start)) {
            return true;
        }
        if (delegate instanceof Repeater) {
            Repeater repeater = (Repeater)delegate;
            return index >= 0 && index < repeater.getSize();
        }
        if (delegate instanceof MultiValueField) {
            Object[] values = (Object[])delegate.getValue();
            return index >= 0 && index < values.length;
        }
View Full Code Here

TOP

Related Classes of org.apache.cocoon.woody.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.