Orbeon has an excellent if lengthy tutorial that, for once, I can honestly say you should read. I really mean it. That said, once you've read it, you'll probably forget it a week later and not want to read it all again. So here is how to get saving working in an XForm (submitting to Java). Use a stock page-flow file and create this view.xhtml
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="save-submission"
method="post"
action=
"http://192.168.1.18:8080/myApplication/SaveForm?instanceId=59&processName=funfest&tracingTag=59"/>
</xforms:model>
<xhtml:head>
What this does is POST the XML of the instance to the URL in the action attribute. Now, the action is kind of funny. If you do not put an absolute URL with an IP, it will be relative to the apps directory of your Orbeon install. Which is annoying if you want to submit to another web application. I'm not sure how to get around this for now. Note that I also wanted to send parameters to the Java, so I had to use ampersand amp semicolon. There's probably a more elegant way.
You can submit to a static page as well to check your work if your Java isn't ready for it. Your browser just sees a blank page, and you can 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>
<xforms:submit submission="save-submission">
<xforms:label>Save</xforms:label>
</xforms:submit>
<xforms:action ev:event="DOMActivate">
<xforms:send submission="save-submission"/>
</xforms:action>
</xhtml:body>
</xhtml:html>
xforms:submit creates a submit button that references save-submission in the model. Then the xforms:action actually links when the button should fire an event. I don't really get how that works just yet, but if you don't have the action, clicking the button does nothing.
One more thing. How do I grab the XML in my Java? It's really easy.
String xmlData="blank";
BufferedReader in = new BufferedReader(request.getReader());
while((inputLine = in.readLine()) != null){
System.out.println(inputLine);
xmlData+=inputLine;
}
in.close();
Just import java.io.BufferedReader. Saving it to Oracle is another post entirely.
No comments:
Post a Comment