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