使用XForms提交加载部分完成的表单

时间:2012-07-19 14:36:14

标签: xml xforms exist-db xsltforms

我正在创建一个小型XForms应用程序来帮助一些协作者创建复杂的元数据记录(TEI标题)。我假设用户可能需要多个会话才能完全填写项目请求的所有元数据。因此,我希望能够将表单数据保存到以项目特定标识符命名的文件,然后允许返回用户从部分完成的表单列表中进行选择,将数据加载回编辑器并继续工作。不幸的是,我无法使加载功能正常运行 - 也就是说,在从列表中选择文件名后,我无法将保存的表单中的数据加载回编辑器。

以下是我模型中的实例:

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

以下是提交内容:

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

以下是文档正文中的相关小部件:

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

这是我对XForms的第一次认真工作,所以也许这里有一些显而易见的东西,我应该能够修复但是我很难过。 (我也想知道我是否在这里传递一个字符串,我应该传递一个URI?)。我正在使用eXistDB附带的XSLTForms处理器

2 个答案:

答案 0 :(得分:1)

网络分析器当然是浏览器调试器中用于检查XSLTForms生成的HTTP请求是否正常的最佳工具。

例如,您熟悉Firebug吗?

以下测试用例对我有用:

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

感谢您的反馈!

-Alain

答案 1 :(得分:1)

我没有看到任何明显的错误,但是(如果你还在为此而战)这里有一些事情要做:

Choose file:控件附近的文档中添加这样的内容。 (我在这里打破了易读性;你可能需要撤销它。)

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

这应显示您load提交的URI。

然后手动取消引用该URI,看看是否可以。 (如果你不能,你就找到了问题。)

如果取消引用URI工作但不能自动工作,请尝试对URI进行硬编码(目前),因此无论用户选择哪个文件,所提供的文件都是您硬编码的文件。即使用文字单引号字符串替换concat()属性中的xf:resource/@value表达式:value="'http://localhost...'"如果失败,请检查服务器日志以查看HTTP使用的URI {{1请求。 (有时当我粗心大意的时候,我忽略了我的提交将提交默认实例的内容作为查询参数,除非我采取措施说不要;然后我必须再次查找并解决问题。)< / p>