OK, Matt called me on it, so I packaged up a small example of what I did, 
focusing only on just the form aspect of it and making it as self-contained 
as possible. Any reasonable AxKit should run this (though I have had a few 
quirks with XInclude on one of my boxes...). Just untar the tarball, it makes 
a directory examples which should be somewhere AxKit can serve it from.

To explain brielfly how it works:

login.xsp is our hypothetical XSP page containing a form. It also happens to 
handle the form, but with this system we can handle the form elsewhere if we 
wish, it just made the example nicer to only have one page. Also I just 
generated a bit of XML when you submit the form, normally I would send the 
parameters to one of my taglibs, but I think you guys can grok that part for 
yourselves...

When you first open the page you end up with an <fm:form/> tag containing the 
included contents of the file loginform.xml, which is the description of the 
default appearance of the form. The <fm:overrides/> element then specifies 
any changes we want to make to the form. It can add in extra fields, supply 
values, etc. Obviously this part can be generated with perl code or a taglib 
as required, just as with perform.

2 XSLT stylesheets are used. form_build.xsl just merges the overrides and the 
other elements to create one final form description (don't laugh too hard at 
the XSLT, it was one of the first I wrote and its HARD to merge stuff with 
XSLT!!!). 

The 2nd stylesheet transforms the page into HTML. If you wanted to make a PDF 
say, then obviously you'd have XSLT to do that instead, or WML or whatever. 
This stylesheet includes form_fields.xsl which provides templates that 
generate the actual HTML form field elements, much like the perform XSLT 
stylesheet does.

I THINK the advantages of this approach are that you can reuse the forms very 
easily, even if you want to build something besies a web page with them, and 
the overrides even let you do stuff like change the action etc, so usually 
you can build a create and an update form from the same basic form, which is 
a pretty frequent pattern with webapps.

The other advantage is just that I don't have those pesky callbacks, nor the 
extra 'bookkeeping' fields that perform needs to know what's going on (though 
I had to resort to <xsp:logic/> to achieve some of the same functionality 
here since this page is self-referencing, so its not all for the good).

I'd be interested in what people think as far as the form definition syntax, 
the XSLT, etc. or if you all think I'm just half-crocked etc. :o). This also 
might be a useable starting point for round-tripping forms (I have some other 
machinery that might help with that as well...).

I'm attaching a tarball of the example, but if memory serves me the 
mailinglist strips attachments, so I'm also uploading it to my server, you 
can get it at http://www.giantelectronicbrain.com/loginexample.tgz

I'll be glad to document this on the wiki as well, I just thought it might be 
worth a bit of discussion here first... (and yes I'm the wordiest poster in 
the history of the Universe, so shoot me ;o).
-- 
Tod Harter
Giant Electronic Brain

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to