Monday 12 May 2008

Orbeon example : Syntax for an if statement within an xf:output tag

In order to make Orbeon evaluate the contents of an instance and to respond based on an IF condition, here's some useful syntax.

The example below will output either 'Items' (for multiple items), or 'Item' for one item in an XML document:

Once again, thanks to the Orbeon forum for their assistance with this question:

Friday 9 May 2008

Orbeon: Resolving Parameters to Load an XML Instance

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...

Hope this helps someone.

Orbeon, inline XSLT and GET parameters

A couple of (hopefully) useful notes here -

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:

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 who have been very helpful whenever I've had questions.