سؤال

I am creating a small XForms application to help some collaborators create complex metadata records (TEI headers). I am proceeding on the assumption that users may need more than one session to completely fill in all the metadata requested by the project. So, what I would like to be able to do is save form data to files named with item-specific identifiers and then allow returning users to select from a list of partially-completed forms, load the data back into the editor and resume working. Unfortunately, I cannot get the load functionality working as I expect—that is, I cannot load data from a saved form back into the editor after I select it's file name from a list.

Here are the instances in my model:

<xf:instance id="itemMD" xmlns="http://www.tei-c.org/ns/1.0"
src="http://localhost:8080/exist/rest/db/home/sga/model.sga.metadata.xml"></xf:instance>

<xf:instance id="control-codes" xmlns="">
    <data>
        <boolean1>false</boolean1>
        <output-filename>temp</output-filename>
        <input-filename></input-filename>
    </data>
</xf:instance>

<xf:instance id="file-utils" xmlns="http://exist.sourceforge.net/NS/exist" src="http://localhost:8080/exist/rest/db/home/sga/posted_data/"></xf:instance>

And here are the submission elements:

<xf:submission id="save" method="put"
replace="none">
<xf:resource value="concat('http://localhost:8080/exist/webdav/db/home/sga/posted_data/', instance('control-codes')/output-filename)"></xf:resource>
</xf:submission>

<xf:submission id="load" method="get" replace="instance" instance="itemMD">
<xf:resource value="concat('http://localhost:8080/exist/webdav/db/home/sga/posted_data/', instance('control-codes')/input-filename)">
</xf:resource>
<xf:message ev:event="xforms-submit-error">Cannot load!</xf:message>
</xf:submission>

And here are the relevant widgets in the document body:

<div id="loader" class="span4 offset8">
<xf:select1 id="load-from-file" ref="instance('control-codes')/input-filename">
<xf:label>Choose file: </xf:label>
<xf:itemset nodeset="instance('file-utils')//exist:resource">
<xf:label ref="@name"></xf:label>
<xf:value ref="@name"></xf:value>
</xf:itemset>
</xf:select1>
<xf:submit submission="load">
<xf:label>Load</xf:label>
</xf:submit>
</div>

This is my first serious work with XForms so perhaps there is something obvious here that I should have been able to fix but I am stumped. (I am also wondering if I am passing a string here where I should be passing a URI?). I am using the XSLTForms processor included with eXistDB

هل كانت مفيدة؟

المحلول

Surely a network profiler is the best tool within a browser debugger for checking if the HTTP requests generated by XSLTForms are OK.

Are you familiar with Firebug, for example?

The following test case works for me:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events">
 <head>
   <title>Save-Load</title>
   <xf:model>
           <xf:instance id="itemMD">
                <data xmlns=""/>
            </xf:instance>
            <xf:instance id="control-codes" xmlns="">
                <data>
                    <boolean1>false</boolean1>
                    <output-filename>temp.xml</output-filename>
                    <input-filename>temp.xml</input-filename>
                </data>
            </xf:instance>
            <xf:submission id="save" method="put" replace="none">
                <xf:resource value="concat('http://localhost/direct/', instance('control-codes')/output-filename)"/>
            </xf:submission>
            <xf:submission id="load" method="get" replace="instance" instance="itemMD">
                <xf:resource value="concat('http://localhost/direct/', instance('control-codes')/input-filename)"/>
                <xf:message ev:event="xforms-submit-error">Cannot load!</xf:message>
            </xf:submission>
        </xf:model>
 </head>
 <body>
    <xf:input ref=".">
        <xf:label>Data: </xf:label>
    </xf:input>
    <br/>
    <xf:input ref="instance('control-codes')/output-filename">
        <xf:label>Output File: </xf:label>
    </xf:input>
    <xf:submit submission="save">
        <xf:label>Save</xf:label>
    </xf:submit>
    <br/>
    <xf:input ref="instance('control-codes')/input-filename">
        <xf:label>Input File: </xf:label>
    </xf:input>
    <xf:submit submission="load">
        <xf:label>Load</xf:label>
    </xf:submit>
   <br/>
 </body>
</html>

Thank you for your feedbacks!

-Alain

نصائح أخرى

I don't see anything obvious wrong, but (if you are still fighting with this) here are some things to do:

Add something like this to your document, near the Choose file: control. (I've broken lines for legibility here; you may need to undo that.)

  <div>Debugging:
    <xf:output value = 
       "concat('http://localhost:8080',
               '/exist/webdav/db/home',
               '/sga/posted_data/',
               instance('control-codes')/input-filename
               )">
      <xf:label>URI for document request: </xf:label>
    </xf:output>
  </div>

That should display the URI your load submission is fetching.

Then dereference that URI, manually, to see whether you can. (If you can't, you've found the issue.)

If dereferencing the URI works manually but not automatically, try hard-coding the URI (for the moment) so no matter what file the user selects, the file served is the one you hard-coded. I.e. replace the concat() expression in the xf:resource/@value attribute with a literal single-quoted string: value="'http://localhost...'" If that fails, check the server logs to see just what URI was used for the HTTP GET request. (Sometimes when I've been careless I've neglected that my submission will submit the contents of the default instances as query parameters, unless I take steps to say not to; then I have to look them up again and fix things.)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top