Tuesday, March 11, 2008

Orbeon XForms: Loading a form from Java

Go read the lengthy tutorial if you have time. Here's how to do it quickly. The basic idea is the same as saving-- use a submission in the model and an event-- but instead of using the post method you use the get method (btw, you can type any method name you like, but the webserver will throw a 405 error if it doesn't recognize it). Use a stock page-flow file and create this view.xhtml which will load data when the form loads (you can use a load button instead by combining this blog post with the previous one about linking a button to a submission event):



First off, lets get the header out of the way


<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:f="http://orbeon.org/oxf/xml/formatting"
xsl:version="2.0">


<xhtml:head>
<xhtml:title>Test Save</xhtml:title>


Now I'm going to define a model for the data.


<xforms:model> 
<xforms:instance id="main">
<name/>
</xforms:instance>


Before the model is done, we need to add a submission to the model.



   <xforms:submission id="load-submission" serialization="none"
method="get"
action=
"http://192.168.1.18:8080/myApplication/LoadForm?instanceId=59&amp;processName=funfest&amp;tracingTag=59"
replace="instance" instance="main"/>
</xforms:model>
<xhtml:head>
<xforms:send ev:event="xforms-ready" submission="load-submission"/>


What this does is a "get" to the URL in the action. serialization="none" attribute specifies that you don't want to send XML instance data with this submission (I'm trying to load the form on startup so it would be pointless). The replace="instance" attribute specifies that the result of the submission has to be stored into an instance. The instance="books-instance" attribute specifies the identifier of the instance into which the result must be stored.


Now we need an event to fire when the page loads. "xforms-ready" is such an event.


        <xforms:send ev:event="xforms-ready" submission="load-submission"/>

You can submit to a static page to check your work if your Java isn't ready for it. Throw some XML into the static page and check the server log to make sure everything else went well.


Lets finish up the view.xhtml. We still need a body and a submit button.



<xhtml:body>


<f:xml-source>
var1: <xsl:copy-of select="doc('input:instance')"/>
</f:xml-source>

<xforms:input ref="/name">
<xforms:label>Name:</xforms:label>
</xforms:input>

</xhtml:body>
</xhtml:html>


What should the XML I paste in my static file look like?



<?xml version="1.0" encoding="UTF-8"?>
<name xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:f="http://orbeon.org/oxf/xml/formatting" xmlns:ev="http://www.w3.org/2001/xml-events">go go power rangers</name>


Whole lot of namespaces for not much data but it works...

No comments:

Labels

Blog Archive

Contributors