Hi,
I sent this message previously, but I guess the subject wasn't explicit enough. I resend it with another subject, hoping someone will find something useful for me...
I would like to know what's the difference between Forms.showForm() and cocoon.sendPageAndWait().
I keep on trying to do a dynamic form, with widgets appearing conditionnally to what the user wishes, and I read that JXTemplate generator is good for this.
But my problem is that when I use it, I'm supposed to just change the template.xml file. Everything else is supposed to work normally.
So I use a flowscript, in which I create a form object and send it to the pipeline with form.showForm :
************** This is my - incredibly powerful ! - function : ****************************
function sendForm(){ var form = new Form("forms/definitions.xml"); form.showForm("display-form"); }
************* And this is the pipeline : **********************
<map:pipelines>
<map:pipeline>
<map:match pattern="form.html">
<map:call function="sendForm"/>
</map:match> <map:match pattern="*.continue">
<map:call continuation="{1}"/>
</map:match>
<map:match pattern="display-form">
<map:generate type="jx" src="forms/template.xml"/>
<map:transform type="forms"/>
<map:transform src="style/forms-styling.xsl"/> <!-- this is just styling -->
<map:serialize type="html"/>
</map:match>
</map:pipeline> </map:pipelines>
****** This is my definitions.xml file : **************
<fd:form xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"> <fd:widgets> <fd:field id="field1"> <fd:label>Please fill this : </fd:label> <fd:datatype base="string"/> </fd:field> </fd:widgets> </fd:form>
***** This is my template.xml file : *************
<jx:template
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">
<jx:import uri="scripts/template.jx"/>
<html>
<head/> <body>
<ft:form-template action="${continuation.id}.continue" method="POST">
<ft:widget-label id="field1"/>
<ft:widget id="field1"/>
<br/>
</ft:form-template>
</body>
</html>
</jx:template>
*************** Finally, this is the template.jx file I use. It's for the moment the basic jx file provided with cocoon. ***************
<jx:template xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
<jx:macro name="form-template" targetNamespace="http://apache.org/cocoon/forms/1.0#template"> <jx:parameter name="action"/> <jx:parameter name="method"/>
<fi:form-template xmlns:fi="http://apache.org/cocoon/forms/1.0#instance"
action="${action}" method="${method}">
<jx:set var="context_widget_" value="#{.}"/>
<jx:evalBody/>
</fi:form-template>
</jx:macro>
<jx:macro name="widget" targetNamespace="http://apache.org/cocoon/forms/1.0#template"> <jx:parameter name="id"/> <jx:set var="context_widget_" value="${context_widget_.lookupWidget(id)}"/>
<jx:set var="list_" value="${java.util.LinkedList()}"/>
<jx:set var="buffer_" value="${Packages.org.apache.cocoon.forms.generation.SaxBuffer(list_)}"/>
<jx:if test="${empty locale}">
<jx:set var="locale" value="${java.util.Locale.getDefault()}"/>
</jx:if>
${context_widget_.unwrap().generateSaxFragment(buffer_, locale)}
<jx:set var="endElement_" value="${list_.removeLast()}"/>
${buffer_.toSAX(cocoon.consumer)}
<jx:evalBody/>
${endElement_.send(cocoon.consumer)}
</jx:macro>
<jx:macro name="repeater-widget-label" targetNamespace="http://apache.org/cocoon/forms/1.0#template"> <jx:parameter name="id"/> <jx:parameter name="widget-id"/>
${context_widget_.lookupWidget(id).unwrap().generateWidgetLabel(this['widget-id'], cocoon.consumer)}
</jx:macro>
<jx:macro name="widget-label" targetNamespace="http://apache.org/cocoon/forms/1.0#template">
<jx:parameter name="id"/>
${context_widget_.lookupWidget(id).unwrap().generateLabel(cocoon.consumer)}
</jx:macro>
<jx:macro name="repeater-size" targetNamespace="http://apache.org/cocoon/forms/1.0#template">
<jx:parameter name="id"/>
${context_widget_.lookupWidget(id).unwrap().generateSize(cocoon.consumer)}
</jx:macro>
<jx:macro name="repeater-widget" targetNamespace="http://apache.org/cocoon/forms/1.0#template" xmlns:ft="http://apache.org/cocoon/forms/1.0#template"> <jx:parameter name="id"/>
<jx:set var="repeater_" value="${context_widget_.lookupWidget(id)}"/>
<jx:set var="lastRow_" value="${repeater_.length - 1}"/>
<jx:forEach varStatus="loop_" begin="0" end="${lastRow_}">
<jx:set var="context_widget_" value="${repeater_.getRow(loop_.index)}"/>
<jx:evalBody/>
</jx:forEach>
</jx:macro>
<jx:macro name="continuation-id" targetNamespace="http://apache.org/cocoon/forms/1.0#template"> <fi:continuation-id xmlns:fi="http://apache.org/cocoon/forms/1.0#instance">${cocoon.continuation.id}</fi:continuation-id>
</jx:macro>
</jx:template>
When I do this, it's supposed to display a form. Instead, I have the following error :
"org.apache.cocoon.ProcessingException: Failed to execute pipeline.: file:/users/shared/cocoon/build/webapp/metadata/forms/template.xml:13:71:TypeError: [EMAIL PROTECTED]: NOT_FOUND is not a function. (resource://org/apache/cocoon/components/flow/javascript/fom/fom_system.js; line 19)"
But if I replace Forms.showForm() with cocoon.sendPageAndWait(), I have no error. Obviously, as there is no reference to definitions.xml in the whole process when I do this, no form appears :P.
That's why I wonder the difference between these two functions, and, widerly :
"What did I wrong ?"
Cheers,
David
-- ************************************ David Verdin GES / ENSAR - laboratoire d'informatique 65, rue de St Brieuc CS 84 215 35 042 Rennes cedex e-mail : [EMAIL PROTECTED] t�l : 02 23 48 54 58 fax : 02 23 48 54 50 ************************************
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
