You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Johan Stuyts <jo...@hippo.nl> on 2003/04/17 14:31:19 UTC

XML Form use cases

At our company we are going to use XMLForm & Flow to build an
application. It is working great, but we have run into some problems (or
think we are going to) with the following use cases:


Use case A: Add an item to a list of items
----------
As part of a larger form the user can enter zero or more subitems.
Initially the form will have space for 'n' items, but the user must be
able to add extra lines to the form. (e.g. a form with personal details
with a list of favorite URLs)

However, the validation that occurs on the form should not be performed
when the 'add line' button is pressed, but should be performed when the
final 'commit' button is pressed.


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)


Use case C: Action buttons for different flows
----------
Some forms can have multiple submits which select different flows
through the application. (e.g. a login screen with a user name, password
and 'login' button, and an email address and a 'send my login details'
button)


To implement these use cases, it is necessary that the function that
calls 'sendView' is able to easily determine which button was pressed.
For use case B it is also necessary to determine which button of the
same button 'type' was pressed.

Use case A has been implemented with a modified version of 'sendView'.
It looks up the validation phase name to use using a Java Map which gets
passed in instead of the validation phase name. The validation phase
name is looked up using the button caption. (Both the usage of a Java
Map and using the button caption for lookup are quick hacks)

Here are some questions and thoughts:
- Should I use the 'cancel'-button construct which is mentioned in the
comment of 'prepare()' of the Java action class of the XMLForm wizard
tutorial? If so, how do I use this in Flow?
- I think the 'id' attribute of a submit control in an XMLForm
definition should be added to the name of the HTML submit button. The
XMLForm (framework) should give easy access to this name after a
successful (no violations) submit.
- The repeated submit controls should have a number added to the name of
the HTML submit button. The XMLForm (framework) should give easy access
to this number too. I do not know whether this number should be
generated by the XMLForm framework. After which the user flow function
must map the number to an object. Or whether it can be an object ID
supplied by the form document/bean.
- A map (JavaScript/Java/...) should be passed to 'sendView' instead of
a validation phase name. The keys are the 'id' attributes of the submit
controls in the XMLForm document. The values are the validation phase
names.
- Another thing I've been thinking about is forwarding or passing
through violations in the case of use case A. Suppose somebody tries to
commit the data, but it is not complete. The same form will return with
violations. If the person then adds an extra line to the subitems, the
violations won't show up anymore because no (or limited) validation is
done when adding a line. The person will only see the previous
violations when he tries to commit the data again. Would it be nice to
specify blocking and non-blocking validation phases for a button? e.g.
commit: blocking = completeForm; add line: blocking = noEmptyURLs &
non-blocking = completeForm
- How to perform validation for use case B is still unclear. It would be
nice if only the item the submit control belongs to could be validated.
Validation for the other items would be non-blocking.

Johan Stuyts <johan at hippo dot nl>
www.hippo.nl


Re: XML Form use cases

Posted by Sylvain Wallez <sy...@anyware-tech.com>.
Johan Stuyts wrote:

>At our company we are going to use XMLForm & Flow to build an
>application. It is working great, but we have run into some problems (or
>think we are going to) with the following use cases:
>
>
>Use case A: Add an item to a list of items
>----------
>As part of a larger form the user can enter zero or more subitems.
>Initially the form will have space for 'n' items, but the user must be
>able to add extra lines to the form. (e.g. a form with personal details
>with a list of favorite URLs)
>
>However, the validation that occurs on the form should not be performed
>when the 'add line' button is pressed, but should be performed when the
>final 'commit' button is pressed.
>

I have a modified version of XMLFormTransformer on my HD that allows 
this : you can flag a <xf:repeat> so that it's also inserted as a 
template after the "normal" instances. This template is then used on the 
client-side to add new instances of the repeat contents, without going 
back to the server.

>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)
>
>
>Use case C: Action buttons for different flows
>----------
>Some forms can have multiple submits which select different flows
>through the application. (e.g. a login screen with a user name, password
>and 'login' button, and an email address and a 'send my login details'
>button)
>

I just ran into this need and I'm happy to see that it's now 
implemented. Thanks, Christopher !

<snip/>

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }



Re: XML Form use cases

Posted by Christopher Oliver <re...@verizon.net>.
Johan,

Thanks for taking the time to describe these use cases. For multi-button 
forms I've modified XMLFormTransformer so that it preserves the submit 
id (instead of overwriting it with the continuation id). That way you'll 
still at least be able to find out which button was pressed. I've added 
a getSubmitId() function to XForm, so you can now find out which button 
was pressed in your flow script:

xform.sendView("userIdentity",
                   "flow/userIdentity.xml",
                   function(xform) {
             print("button="+xform.getSubmitId());
          });
 
However, I'm hesitant to fully address your use cases at this point 
because I think XMLForm needs to be updated to be in line with the more 
recent W3 specification, before we can design a solution -- since that 
will result in non-backward-compatible changes to XMLForm that would 
affect any design we came up with now.

Regards,

Chris




Johan Stuyts wrote:

>At our company we are going to use XMLForm & Flow to build an
>application. It is working great, but we have run into some problems (or
>think we are going to) with the following use cases:
>
>
>Use case A: Add an item to a list of items
>----------
>As part of a larger form the user can enter zero or more subitems.
>Initially the form will have space for 'n' items, but the user must be
>able to add extra lines to the form. (e.g. a form with personal details
>with a list of favorite URLs)
>
>However, the validation that occurs on the form should not be performed
>when the 'add line' button is pressed, but should be performed when the
>final 'commit' button is pressed.
>
>
>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)
>
>
>Use case C: Action buttons for different flows
>----------
>Some forms can have multiple submits which select different flows
>through the application. (e.g. a login screen with a user name, password
>and 'login' button, and an email address and a 'send my login details'
>button)
>
>
>To implement these use cases, it is necessary that the function that
>calls 'sendView' is able to easily determine which button was pressed.
>For use case B it is also necessary to determine which button of the
>same button 'type' was pressed.
>
>Use case A has been implemented with a modified version of 'sendView'.
>It looks up the validation phase name to use using a Java Map which gets
>passed in instead of the validation phase name. The validation phase
>name is looked up using the button caption. (Both the usage of a Java
>Map and using the button caption for lookup are quick hacks)
>
>Here are some questions and thoughts:
>- Should I use the 'cancel'-button construct which is mentioned in the
>comment of 'prepare()' of the Java action class of the XMLForm wizard
>tutorial? If so, how do I use this in Flow?
>- I think the 'id' attribute of a submit control in an XMLForm
>definition should be added to the name of the HTML submit button. The
>XMLForm (framework) should give easy access to this name after a
>successful (no violations) submit.
>- The repeated submit controls should have a number added to the name of
>the HTML submit button. The XMLForm (framework) should give easy access
>to this number too. I do not know whether this number should be
>generated by the XMLForm framework. After which the user flow function
>must map the number to an object. Or whether it can be an object ID
>supplied by the form document/bean.
>- A map (JavaScript/Java/...) should be passed to 'sendView' instead of
>a validation phase name. The keys are the 'id' attributes of the submit
>controls in the XMLForm document. The values are the validation phase
>names.
>- Another thing I've been thinking about is forwarding or passing
>through violations in the case of use case A. Suppose somebody tries to
>commit the data, but it is not complete. The same form will return with
>violations. If the person then adds an extra line to the subitems, the
>violations won't show up anymore because no (or limited) validation is
>done when adding a line. The person will only see the previous
>violations when he tries to commit the data again. Would it be nice to
>specify blocking and non-blocking validation phases for a button? e.g.
>commit: blocking = completeForm; add line: blocking = noEmptyURLs &
>non-blocking = completeForm
>- How to perform validation for use case B is still unclear. It would be
>nice if only the item the submit control belongs to could be validated.
>Validation for the other items would be non-blocking.
>
>Johan Stuyts <johan at hippo dot nl>
>www.hippo.nl
>
>
>  
>



Re: XML Form use cases

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
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="cocoon-action-{@id}" 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="cocoon-action-{@id}" 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


Re: XML Form use cases

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
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.

public class Coverage extends PersistableBean {
	private String name;
	private String description;
	private Coverage parent;
	private Set children; // this one wants a list of edit buttons

The action needs to be submitted, to the 'forward' continuation.

The Flowscript function looks like this:
(the 'exit', 'save' and 'editParent' commands are working)

function editCoverage (xform, reg) {
   while (true) {						// event handling loop
     xform.sendView ("/coverage/edit.xml");
     var coverage = xform.getModel();
     var command = xform.getSubmitId();
     if (command == "exit") {
       break;						// don't save, exit
     } else if (command == "save") {
       reg.saveCoverage(coverage);		// save and carry on
     } else if (command == "editParent") {
       xform.setModel(coverage.getParent()); // switch to parent
       editCoverage(xform, reg);		// recurses, calls sendView()
       xform.setModel(coverage);		// now back to child
     } else if (command == "editChild") {
       var child; 						// get child ???????? how?
       xform.setModel(child);			// switch to child
       editCoverage(xform, reg); 		// recurses, calls sendView()
       xform.setModel(coverage);		// now back to parent
     } else if (command == "newChild") {
       newChildCoverage(xform, reg);	// calls sendView()
     } else if (command == "delete") {
       deleteCoverage(xform, reg);		// calls sendView()
    } else if (command == "move") {
       moveCoverage(xform, reg);		// calls sendView()
    }
     if (coverage == null) break;
     if (reg = null) {
       xform.sendView ("/coverage/fatal.xml");
       break;
     }
   }
}

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



Thanks for any feedback.

regards Jeremy