cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Spaeth <>
Subject RE: XML Form use cases
Date Thu, 19 Jun 2003 13:46:14 GMT
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:


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) {
			else if (page[0] == VIEW_COMMAND) {
			else if (page[0] == CREATE_COMMAND) {
			else if (page[0] == UPDATE_COMMAND) {
			else if (page[0] == REMOVE_COMMAND) {
			else if (page[0] == BROWSE_HISTORY_COMMAND) {
			else {
	catch (e) {
	finally {
		if (mgr != null) {
			mgr = null;
		if (model != null) {
			delete model;
			model = null;


-----Original Message-----
From: Jeremy Quinn [] 
Sent: Thursday, June 19, 2003 7:44 AM
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.


> 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:repeat nodeset="children">
     <xf:submit value="Edit Child" id="editChild" continuation="forward" 
       <xf:label><xf:output ref="name"/></xf:label>
       <xf:hint>Edit Child Coverage</xf:hint>
       <beanid><xf:output ref="id"/></beanid> <!-- extra tag -->
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:when test="@src">
			<input name="cocoon-action-{@id}" type="image" 
				<xsl:copy-of select="@*[not(name()='id')]"/>
				<xsl:apply-templates select="xf:hint"/>
		<xsl:when test="beanid"> <!-- modification -->
type="submit" value="{xf:label/text()}">
				<xsl:copy-of select="@*[not(name()='id')]"/>
				<xsl:apply-templates select="xf:hint"/>
			<input name="cocoon-action-{@id}" type="submit" 
				<xsl:copy-of select="@*[not(name()='id')]"/>
				<xsl:apply-templates select="xf:hint"/>

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);
	redirect("" + 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

View raw message