Title: RE: XML Form use cases

I recently ran into this same use case scenario when using cocoon myself. 
I just figured I wasn't going to try to make cocoon do something it didn't seem was supported yet.  Therefore, instead of switching on the submit id, I use a multi-item form control such as a select1 to encode the submid id and a single forward continuation submit button.  Then, in the flowscript, I  simply use:

cocoon.request.getParameterValues("/page")

to reference the submit id which is then mapped via the flowscript into the page to forward the user to.  This method has the additional benefit of allowing any other form submission information as well.

My actual flow looks like:

function equipmentTroubles(form) {
        var model = null,
                equipmentTroubleDoc = null,
                mgr = null;
        try {
                // now loop and send the page specified in the request parameter 'page'
                var page = null;
                while (true) {
                        page = cocoon.request.getParameterValues("/page");
                        if (page == null) {
                                ...
                                form.setModel(model);
                               
                                form.sendView(INDEX_PAGE);
                        }
                        else if (page[0] == VIEW_COMMAND) {
                                form.sendView(VIEW_PAGE);
                        }
                        else if (page[0] == CREATE_COMMAND) {
                                form.sendView(CREATE_PAGE);
                        }
                        else if (page[0] == UPDATE_COMMAND) {
                                form.sendView(UPDATE_PAGE);
                        }
                        else if (page[0] == REMOVE_COMMAND) {
                                form.sendView(REMOVE_PAGE);
                        }
                        else if (page[0] == BROWSE_HISTORY_COMMAND) {
                                form.sendView(BROWSE_HISTORY_PAGE);
                        }
                        else {
                                form.sendView(ERR_NOT_FOUND_PAGE);
                        }
                }
        }
        catch (e) {
                print("Exception!");
                print(e);
        }
        finally {
                if (mgr != null) {
                        mgr.dispose();
                        mgr = null;
                }
               
                if (model != null) {
                        delete model;
                        model = null;
                }
        }
}

Jon

-----Original Message-----
From: Jeremy Quinn [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 19, 2003 7:44 AM
To: [EMAIL PROTECTED]
Subject: Re: XML Form use cases


On Sunday, June 15, 2003, at 02:20 PM, Jeremy Quinn wrote:

>
> On Thursday, April 17, 2003, at 01:31 PM, Johan Stuyts wrote:
>
> <snip/>
>
>> Use case B: A button per item
>> ----------
>> A lot of forms contain lists. It is handy to add one or more buttons
>> to
>> each item sometimes. (e.g. a 'delete' button for each item in a
>> shopping
>> cart)
>
> <snip/>
>
> I am trying to add an 'edit' action to each member of a Set of child
> objects on a Bean I am working on with JXForms.
>

<snip/>

>
> Has anybody got any ideas how you would identify which child's edit
> button was pressed?

OK, this is the only way I can make this work ...... but it is a bit of
a hack!!!

I have 3 <xf:form/>(s) in the <document/> sent to the client, they each
have the same '@id'.

Form[0] contains fields that can get edited, it has a single 'submit'
button. Clicking this sends the data to the continuation. This is for
saving the edited data of the entity we are currently working on.

Form[1] has a set of 'submit' buttons (editParent, moveThis,
removeThis, changeThisType, etc.), but no fields. Each submit button
has an 'id'. Clicking one of these submits to the continuation with no
form data, ie. it does not update the sate of the entity.

The flow script identifies which button was pressed by calling
xform.getSubmitId(), as normal.

Form[2] is for selecting a child to edit (again, it has no fields). I
add an extra tag to the submit button, thus:

<xf:group>
   <xf:label>Children</xf:label>
   <xf:repeat nodeset="children">
     <xf:submit value="Edit Child" id="editChild" continuation="forward"
class="button">
       <xf:label><xf:output ref="name"/></xf:label>
       <xf:hint>Edit Child Coverage</xf:hint>
       <beanid><xf:output ref="id"/></beanid> <!-- extra tag -->
     </xf:submit>
   </xf:repeat>
</xf:group>
       
I process this with a modified JXForm2html.xsl:

  <xsl:template match="xf:submit">
         <!-- the id attribute of the submit control is sent to the server -->
         <!-- as a conventional Cocoon Action parameter of the form
cocoon-action-* -->
        <xsl:choose>
                <xsl:when test="@src">
                        <input name="[EMAIL PROTECTED]" type="image"
value="{xf:label/text()}">
                                <xsl:copy-of select="@*[not(name()='id')]"/>
                                <xsl:apply-templates select="xf:hint"/>
                        </input>
                </xsl:when>
                <xsl:when test="beanid"> <!-- modification -->
                        <input name="{concat('cocoon-action-',@id,'_',beanid)}"
type="submit" value="{xf:label/text()}">
                                <xsl:copy-of select="@*[not(name()='id')]"/>
                                <xsl:apply-templates select="xf:hint"/>
                        </input>
                </xsl:when>
                <xsl:otherwise>
                        <input name="[EMAIL PROTECTED]" type="submit"
value="{xf:label/text()}">
                                <xsl:copy-of select="@*[not(name()='id')]"/>
                                <xsl:apply-templates select="xf:hint"/>
                        </input>
                </xsl:otherwise>
        </xsl:choose>
  </xsl:template>

Thereby adding '_ID' to the 'name' of the submit button.

This is then handled by the FlowScript thus:

var command = xform.getSubmitId();
if (command.startsWith("editChild_")) {
        var childId = command.substring(10);
        xform.finish();
        redirect("do.that.voodoo.that.you.do.so.well/" + childId);
} // sorry, been watching 'Blazing Saddles' ;)

As I said, it is a bit of a hack, but it works .....

If anyone comes up with a better way of handling this in the JXForms
framework, I would be happy to hear!!

Hope this helps

regards Jeremy

Reply via email to