Hello,
I am trying to understand the process and minimum requirement for setting up a simple CForm in Cocoon 2.1.5. I have followed the doco and samples where possible but I think I've hit a wall. I have created a simple form, but failed when binding from an XML file with the following error:
org.mozilla.javascript.EvaluatorException: "resource://org/apache/cocoon/forms/flow/javascript/Form.js", line 164: Invalid JavaScript value of type org.mozilla.javascript.UniqueTag
I reduced the form down to a simple single text field bind, but still received the same error.
What I have set up is a simple form called batchUpload with its own dir area as follows:
BASEDIR: cocoon2.1.5/build/webapp/forms-test
Forms: $BASEDIR/forms
Flow: $BASEDIR/flow
Resources: $BASEDIR/resources (this is a copy of the cocoon resources dir build/webapp/samples/blocks/forms/resources, so has the field stylesheets, etc)
Messages: $BASEDIR/messages
Sitemap: $BASEDIR/sitemap.xmap
The sitemap file is as follows:
<?xml version="1.0"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
<map:components>
<map:transformers default="xalan">
<map:transformer name="i18n" src="org.apache.cocoon.transformation.I18nTransformer">
<catalogues default="other">
<catalogue id="other" name="OtherMessages" location="./messages"/>
</catalogues>
<cache-at-startup>true</cache-at-startup>
</map:transformer>
</map:transformers>
</map:components>
<map:flow language="javascript"> <map:script src="flow/batchUpload.js"/> </map:flow>
<map:pipelines> <map:pipeline>
<map:match pattern="batchUpload"> <map:call function="handleForm"> <map:parameter name="function" value="batchUpload"/> <map:parameter name="form-definition" value="forms/batchUpload.xml"/> <map:parameter name="documentURI" value="forms/batchUpload_data.xml"/> <map:parameter name="bindingURI" value="forms/batchUpload_bind.xml"/> </map:call> </map:match>
<map:match pattern="*.continue"> <map:call continuation="{1}"/> </map:match>
<map:match pattern="batchUpload-display-pipeline"> <map:generate src="forms/batchUpload_template.xml"/> <map:transform type="forms"/> <map:transform type="i18n"> <map:parameter name="locale" value="en-US"/> </map:transform> <map:transform src="resources/forms-samples-styling.xsl"/> <map:serialize/> </map:match>
<map:match pattern="batchUpload-success-pipeline.jx"> <map:generate type="jx" src="forms/batchUpload_success.jx"/> <map:serialize/> </map:match> </map:pipeline> </map:pipelines> </map:sitemap>
=====================
The Javascript to do the form load (batchUpload.js), bind and display is as follows (within the form.load() is where the exception mentioned above is thrown)
cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js");
function batchUpload() { var form = new Form("forms/batchUpload.xml"); // added for bind var documentURI = cocoon.parameters["documentURI"];
// parse the document to a DOM-tree var document = loadDocument(documentURI);
// bind the document data to the form form.load(document);
// The showForm function will keep redisplaying the form until // everything is valid form.showForm("batchUpload-display-pipeline"); }
function loadDocument(uri) {
var parser = null;
var source = null;
var resolver = null;
try {
parser = cocoon.getComponent(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
resolver = cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
source = resolver.resolveURI(uri);
var is = new Packages.org.xml.sax.InputSource(source.getInputStream());
is.setSystemId(source.getURI());
return parser.parseDocument(is);
} finally {
if (source != null)
resolver.release(source);
cocoon.releaseComponent(parser);
cocoon.releaseComponent(resolver);
}
}
============
The binding file (batchUpload_bind.xml) is the simplified bding file:
<?xml version="1.0"?>
<fb:context xmlns:fb="http://apache.org/cocoon/forms/1.0#binding" path="/" direction="load" xmlns:fd="http://apache.org/cocoon/forms/1.0#definition">
<fb:value id="bitstreamDirSelect" path="/dc-elements/dc-element1"/>
</fb:context>
==============
The simplified data file (batchUpload_data.xml) is as follows:
<?xml version="1.0"?> <dc-elements> <dc-element1 qualified="true">subject.other</dc-element1> </dc-elements>
===================
The form definition (batchUpload.xml) is as follows:
<?xml version="1.0"?> <fd:form xmlns:fd="http://apache.org/cocoon/forms/1.0#definition" xmlns:i18n="http://apache.org/cocoon/i18n/2.1"> <fd:widgets>
<fd:upload id="metafileSelect" required="true"> <fd:label>Metadata File:</fd:label> </fd:upload>
<fd:field id="bitstreamDirSelect" required="true">
<fd:label>Content Directory:</fd:label>
<fd:datatype base="string">
<fd:validation>
<fd:length min="5">
<fd:failmessage>This field must be at least five chars</fd:failmessage>
</fd:length>
</fd:validation>
</fd:datatype>
</fd:field>
<fd:field id="bitstreamNameField" required="true"> <fd:label>Filename Field:</fd:label> <fd:datatype base="string"/> <fd:selection-list> <fd:item value="title"/> <fd:item value="library category"/> <fd:item value="filename"/> <fd:item value=" other categories"/> </fd:selection-list> </fd:field>
<fd:field id="licenseFile" required="false"> <fd:label>License File:</fd:label> <fd:datatype base="string"/> </fd:field>
<fd:repeater id="DCMap" initial-size="3"> <fd:label>Dublin Core Mapping</fd:label> <fd:widgets> <fd:field id="DCElement"> <fd:datatype base="string"/> <fd:label>Dublin Core Field</fd:label> <fd:selection-list> <fd:item value=""/> <fd:item value="title"/> <fd:item value="subject.lcc"/> <fd:item value="subject.other"/> </fd:selection-list> </fd:field> <fd:field id="metadataField" required="true"> <fd:datatype base="string"/> <fd:label>Metadata Field</fd:label> <fd:selection-list> <fd:item value="title"/> <fd:item value="library category"/> <fd:item value="filename"/> <fd:item value="other categories"/> </fd:selection-list> </fd:field> <fd:field id="separator"> <fd:datatype base="string"/> <fd:label>Separator</fd:label> </fd:field> </fd:widgets> </fd:repeater>
<fd:repeater id="results" initial-size="3">
<fd:label>Results</fd:label>
<fd:widgets>
<fd:output id="failedItem">
<fd:datatype base="string"/>
<fd:label>Failed Item</fd:label>
</fd:output>
<fd:output id="failedReason">
<fd:datatype base="string"/>
<fd:label>Failed Reason</fd:label>
</fd:output>
</fd:widgets>
</fd:repeater> </fd:widgets>
</fd:form>
==================
Finally, the template file (batchUpload_template.xml) is as follows:
<?xml version="1.0"?>
<page xmlns:ft="http://apache.org/cocoon/forms/1.0#template"
xmlns:fi="http://apache.org/cocoon/forms/1.0#instance" xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
<title>BatchUpload</title>
<content>
<ft:form-template action="batchUpload" method="POST" enctype="multipart/form-data">
<fi:group>
<fi:styling type="fieldset" layout="columns"/>
<fi:label>Metadata and Content Setup</fi:label>
<fi:items>
<ft:widget id="metafileSelect"/>
<ft:widget id="bitstreamDirSelect"/>
<ft:widget id="bitstreamNameField"/>
<ft:widget id="licenseFile"/>
</fi:items>
</fi:group>
<br/>
<fi:group>
<fi:styling type="fieldset"/>
<fi:label><ft:widget-label id="DCMap"/></fi:label>
<fi:items>
<table cellspacing="10">
<tr>
<th><ft:repeater-widget-label id="DCMap" widget-id="DCElement"/></th>
<th><ft:repeater-widget-label id="DCMap" widget-id="metadataField"/></th>
<th><ft:repeater-widget-label id="DCMap" widget-id="separator"/></th>
</tr>
<ft:repeater-widget id="DCMap">
<tr>
<td><ft:widget id="DCElement"/></td>
<td><ft:widget id="metadataField"/></td>
<td><ft:widget id="separator"/></td>
</tr>
</ft:repeater-widget>
</table>
</fi:items>
</fi:group>
<fi:group> <fi:styling type="fieldset" layout="columns"/> <fi:label>Status Window</fi:label> <fi:items> <ft:widget id="results"/> </fi:items> </fi:group> </ft:form-template> <script> </script> </content> </page>
Anyone know what's behind this error?
Thanks.
Scott.