使用XForms提交加载部分完成的表单
我正在创建一个小型XForms应用程序来帮助一些协作者创建复杂的元数据记录(TEI标头)。我正在继续假设用户可能需要多个会话才能完全填写项目请求的所有元数据。因此,我希望能够将表单数据保存到以特定于项目的标识符命名的文件中,然后允许返回的用户从部分完成的表单中进行选择,将数据加载回编辑器并恢复工作。不幸的是,我无法像我期望的那样获得加载功能 - 也就是说,从列表中选择文件名后,我无法将保存的表单中的数据加载回编辑器。使用XForms提交加载部分完成的表单
下面是在我的模型实例:
<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处理器
当然,网络分析器是浏览器调试器中最好的工具,用于检查由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
我看不出有什么明显的错误,但(如果你还在这个战斗)这里有一些事情要做:
添加像这样到您的文档,靠近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进行硬编码(暂时),所以无论用户选择什么文件,提供的文件是您硬编码的文件。即将xf:resource/@value
属性中的concat()
表达式替换为文字单引号字符串:value="'http://localhost...'"
如果失败,请检查服务器日志以查看HTTP GET
请求使用的URI。 (有时当我粗心大意时,我忽略了我的提交会将默认实例的内容作为查询参数提交,除非我采取措施不说;否则我必须再次查找并修复它们。)
谢谢你这么快回答。我熟悉Firebug和类似的工具。我查看了这些工具的输出,他们让我相信我没有正确使用xforms提交,而不是XSLTForms生成的HTTP请求不正确。 – trevormunoz 2012-07-19 20:30:57
我可以看到,单击表单中的“加载”按钮将调度xforms-submit-error事件(来自XSLTForms调试器),但是当我访问错误消息时,我只能得到“undefined”,不知道如何继续。谢谢。 – trevormunoz 2012-07-19 20:44:18