Friday, 9 May 2008

Ok, so these are my notes regarding our method for getting Orbeon to load an instance based on some parameters that were sent to the XForm. This posting follows on from where my previous post left off:

In the model declaration of view.xhtml, I've created two minimal instances:

I'm also adding this piece in - as discussed in the last post - this resolves the get parameters and stores the information in the instance, so you can access the parameters using XPath:

We're initialising two ev:events; these fire at different times but both should have fired by the time the XForm has been rendered onscreen:

As the form loads, xforms-model-construct-done should fire first; xforms-ready should fire soon after that.

So here's the code for the first submission:

And here's similar code for the second submission - for the sake of example here, I'm using 2 parameters when calling this one...

If you're creating XForms and you're using Orbeon (which is a damn fine choice if you ask me ;)), then you may want to pass params to the form at some stage:

so you call your form using something like this:

To get at the values you pass in, you can do the following:

- Edit the page-flow.xml file in your folder, so you have something like this:

Note here that the default-submission refers to a file:default-submission="/path-to-your/test.xml"

You'll need to create that XML structure, it can have no values or you can put values in there which will act as 'defaults'.

test.xml will look something like this:

in your view.xhtml, in the model, add something like this:

You can now XPath into your parameters using instance('my-params')/first and so on.

If you're using Orbeon 3.7 (either a nightly build or when it's released), you have the option to use the xxforms:get-request-parameter to grab the parameters and put them into an instance. To do this, first create an empty instance in your model:

And create an action (also in the model) like this:

If you call your form with an id parameter, you should find that xf:setvalue will write that request parameter into the params instance.

Finally, it may be the case that you need to fire an XSLT transform inside the view.xhtml. I've heard warnings that this can be expensive in terms of processing, but I found that the following code worked, so thought I'd make a note here.

In the body of your XForm, a block of code like this:

Will be executed by an XSLT processor. That example may be useful to someone.

Thanks go to everyone at the OPS forum http://www.nabble.com/ObjectWeb-OPS---Users-f2537.html who have been very helpful whenever I've had questions.