views:

276

answers:

2

Hi,

I am using the Orbeon Forms solution to generate messages from filled-in web forms.

I read different code snippetse in Orbeon's wiki on XForms submission from a pipeline, and I tried different solutions but it doesn't work, and there is no example with a POST from a pipeline, caught by a PFC and sent to an XForms view that receives the posted data (all examples are done in the same page).

I have the following pipeline which is received on his instance input:

pipelineWrite.xpl

<p:config ...>
    <p:param name="instance" type="input"/> <!-- instance containing the data of the form filled by user -->
    <p:param name="data" type="output"/>

    <p:processor name="oxf:java"> <!-- transforms the data into a file -->
        <p:input name="config">
            <config sourcepath="." class="ProcessorWriteCUSDECCD001B"/>
        </p:input>
        <p:input name="input" href="#instance"/>
        <p:output name="output" id="file"/> <!-- XML containing the url of the file -->
    </p:processor>       
</p:config> 

Then there is the PFC which catch the actions :

page-flow.xml

<config xmlns="http://www.orbeon.com/oxf/controller"&gt;

    <page path-info="/CUSDECCD001B/" view="View/ViewForm.xhtml"/> <!-- load the form to be filled in by user -->

    <page path-info="/CUSDECCD001B/write" model="Controller/PipelineWrite.xpl"/> <!-- send the instance of the form filled to the pipeline above -->

    <page path-info="/CUSDECCD001B/success" view="View/ViewSuccess.xhtml"/> <!-- send the instance containing the url of the file to the success view -->

    <epilogue url="oxf:/config/epilogue.xpl"/>
</config> 

Then there is the success view, which is very simple :

ViewSuccess.xhtml

<html ... >
  <head>
    <title>Generation OK</title>
    <xforms:model>
            <xforms:instance id="FILE" src="input:instance">
                <files xmlns="">
                    <file mediaType="" filename="" size="" />
                </files>
            </xforms:instance>
        </xforms:model>
  </head>
  <body>
        Click here to download :
        <xforms:output ref="//file" appearance="xxforms:download">
            <xforms:filename ref="@filename"/>
            <xforms:mediatype ref="@mediatype"/>
            <xforms:label>Download</xforms:label>
        </xforms:output>
  </body>
</html> 

All this process I launched by clicking on the "Save" button in the "ViewModify" page :

ViewModify.xhtml

<xforms:model>
    <xforms:instance id="CUSDECCD001B" src="../apps/CUSDECCD001B/Model/ModelCUSDECCD001B.xml" />
    <xforms:submission id="save-submission" ref="instance('CUSDECCD001B')" action="/CUSDECCD001B/write" replace="instance" instance="CUSDECCD001BFile">
        <xforms:send ev:event="xforms-submit-done" submission="send-to-success"/>
    </xforms:submission>
    <xforms:submission id="send-to-success" method="post" action="/CUSDECCD001B/success" ref="instance('CUSDECCD001BFile')" replace="all"/>
</xforms:model>

  <!-- .... Content of XForms form -->

<xforms:submit submission="save-submission">
    <xforms:label>Save</xforms:label>
</xforms:submit>

The problem is that the post is done well, the PFC catches the action well, load the correct view, but the view is loaded with no data (the view doesn't find the data on his instance input).

I tried with a GET in the view to retrieve the POST data, and that's the same thing. No data is retrieved. So the download button doesn't work.

I hope I'm clear enough to find a solution. Thanks in advance.

+1  A: 

Only an xforms:submission replace="instance" makes sense when used from the oxf:xforms-submission processor. So the result from the submission must return XML, but this won't work here since when you do a submission to an XForms page, HTML is returned.

I assume that you have a form that does a submission replace="all" to /CUSDECCD001B/write. Instead:

  1. Do submission replace="instance" and store the result in an instance.
  2. In pipelineWrite.xpl return the file output of the Java processor directly, without calling the XForms submission processor.
  3. Back in the XForms that does the submission replace="instance" to /CUSDECCD001B/write, when that submission is done (xforms-submit-done) run another submission that POSTs the results to /CUSDECCD001B/success.
Alessandro Vernet
Hi Alessandro. Thanks a lot for your help ! Actually you're right, I should have inserted the XForms code that start the whole process. So, I edited my post to add the "ViewModify" XForms page. Then I tried to apply the modifications you indicated. I think it's almost ok for the items 2/ and 3/ you listed, but last thing is that I don't see how to "store the result in instance" (item 1/).Could you have a look at the new versions of files ? Thanks a lot !
Clem
Clem, the code looks right. So I assume you also have an instance `CUSDECCD001BFile` (since you have `instance="CUSDECCD001BFile"` in the submission). If you don't you'll need to add one, and at first it can contain just about anything. I often put an element `<dummy/>` to make it clear this is just a placeholder.
Alessandro Vernet
A: 

After taking Alessandro adivces into consideration and searching for other code snippets on Orbeon wiki, here is the solution that works fine for me :

The pipeline receiving a filled form instance on his instance input:

piplineWrite.xpl

<p:param name="instance" type="input"/>
<p:param name="data" type="output"/>

<p:processor name="oxf:java">
    <p:input name="config">
        <config sourcepath="." class="ProcessorWrite"/>
    </p:input>
    <p:input name="input" href="#instance"/>
    <p:output name="output" ref="data"/>
</p:processor>

The PFC catching actions and lauching the corresponding one :

page-flow.xml

<config xmlns="http://www.orbeon.com/oxf/controller"&gt;
    <page path-info="/CUSDECCD001B/write" view="Controller/PipelineWrite.xpl"/>
    <page path-info="/CUSDECCD001B/success" view="View/ViewSuccess.xhtml"/>
    <epilogue url="oxf:/config/epilogue.xpl"/>
</config>

The view Success receiving data output after processing :

viewSuccess.xhtml

<html ...>
  <head>
    <xforms:model>
        <xforms:instance id="FILE" src="input:instance"/>
    </xforms:model>
  </head>
  <body>

    <p> Generation Success !</p>

    <div class="toolbar">
        Cliquer to download :
        <xforms:output ref="//file" appearance="xxforms:download">
            <xforms:filename ref="@filename"/>
            <xforms:mediatype ref="@mediatype"/>
            <xforms:label>Download</xforms:label>
        </xforms:output>
    </div>
  </body>
</html>

The view Modify with a "Save" button lauching the whole process :

viewModify.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events"&gt;
  <head>
    <xforms:model>
      <xforms:instance id="CUSDECCD001BFile">
        <dummy xmlns="" />
      </xforms:instance>
      <xforms:submission id="save-submission" ref="instance('CUSDECCD001B')" action="/CUSDECCD001B/write" method="post" replace="instance" instance="CUSDECCD001BFile">
        <xforms:action ev:event="xforms-submit">
          <xforms:send submission="send-submission" />
        </xforms:action>
      </xforms:submission>
      <xforms:submission id="send-submission" ref="instance('CUSDECCD001BFile')" action="/CUSDECCD001B/success" method="post" />
    </xforms:model>
  </head>
  <body>
    ...
    <xforms:submit submission="save-submission">
      <xforms:label>Save</xforms:label>
    </xforms:submit>
  </body>
</html>

The main problems in the previous code snippet and advices given were :

  • the <xforms:instance> must specify a resource="" or at least contains a default content (here <dummy />),
  • the xforms-submit-done event doesn't seem to work or exist. So, I used an xforms-submit event.
Clem