You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Colin Paul Adams <co...@colina.demon.co.uk> on 2004/07/02 11:31:55 UTC
CForms Binding to XML file sample
It seems to me there is something seriously wrong with the binding to
xml file sample.
If I add a new row to the table at the bottom, I get the following XML
output:
<data>
-
<wrapper>
-
<context>
-
<info>
<email boolBindingWorks="false">yourname@yourdomain.com</email>
<number value="3"/>
<choose value="true"/>
-
<phone cntr="32">
<zone>2</zone>
<number>2222222</number>
</phone>
</info>
<ipaddress changed="false">10.34.44.78</ipaddress>
<birthday>1960-04-10</birthday>
-
<drinks>
<drink>Jupiler</drink>
<drink>Hoegaarden</drink>
</drinks>
-
<contacts>
-
<contact id="1" row-state="original">
<firstname>Lucien</firstname>
<lastname>Vandevelde</lastname>
<phone nr="+32-2-2222222"/>
<email>lv@vdvld.be</email>
</contact>
-
<contact id="2" row-state="original">
<firstname>Joris</firstname>
<lastname>Veldweghel</lastname>
<phone nr="+32-59-595959"/>
<email>jrsvldwghl@hotmail.com</email>
</contact>
-
<!--
template inserted by the binding for new rows (mapping new nodes)
-->
-
<contact id="" row-state="new">
<firstname>fred</firstname>
<lastname>jones</lastname>
<phone nr="+44-1772-498247"/>
<email>colin@colina.demon.co.uk</email>
</contact>
</contacts>
</context>
</wrapper>
</data>
Note that the id field for the new row is an empty attribute.
This is no good - if the repeater widget requires unique ids (and note
that these if attributes are not of type ID or xs:ID as they do not
begin with a letter, but that's another issue), then why is there not
an id assigned to the new row?
If two rows were added, immediately the ids would no longer be
unique.
And if this data file were read in again, there would be a problem.
--
Colin Paul Adams
Preston Lancashire
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: CForms Binding to XML file sample
Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On 3 Jul 2004, at 17:22, Joerg Heinicke wrote:
> On 03.07.2004 18:16, Colin Paul Adams wrote:
>
>> Joerg> That's indeed difficult. Only help is the usage of print().
>> But where does the output go to?
>
> To the console.
>
> There is also a logging function IIRC, something like log() or
> cocoon.log(). This would probably go to flow.log.
cocoon.log.debug ("message");
cocoon.log.info ("message");
cocoon.log.warn ("message");
cocoon.log.error ("message");
You can adjust which level of logging appears in the flow log by
changing the level in WEB-INF/logkit.xconf.
<category log-level="INFO" name="flow">
<log-target id-ref="flow"/>
<log-target id-ref="error"/>
</category>
The default is 'INFO' which would show 'info', 'warn' and 'error'.
HTH
regards Jeremy
--------------------------------------------------------
If email from this address is not signed
IT IS NOT FROM ME
Always check the label, folks !!!!!
--------------------------------------------------------
Re: CForms Binding to XML file sample
Posted by Joerg Heinicke <jo...@gmx.de>.
On 03.07.2004 18:16, Colin Paul Adams wrote:
> Joerg> That's indeed difficult. Only help is the usage of print().
>
> But where does the output go to?
To the console.
There is also a logging function IIRC, something like log() or
cocoon.log(). This would probably go to flow.log.
Joerg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: CForms Binding to XML file sample
Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "Joerg" == Joerg Heinicke <jo...@gmx.de> writes:
Joerg> That's indeed difficult. Only help is the usage of print().
But where does the output go to?
Joerg> The code should be something like:
Joerg> <fb:javascript id="id" path="@id" direction="save">
Joerg> <fb:save-form> var appValue = jxpathPointer.getValue(); if
Joerg> (appValue == '') { var precSiblId =
Joerg> jxpathContext.getValue("../preceding-sibling::contact/@id");
Joerg> var newId = Number(precSiblId) + 1
Joerg> jxpathPointer.setValue(newId.toFixed(0)); } </fb:save-form>
Joerg> </fb:javascript>
Ta.
With one alteration to suit my xml file, it works fine.
--
Colin Paul Adams
Preston Lancashire
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: CForms Binding to XML file sample
Posted by Joerg Heinicke <jo...@gmx.de>.
On 03.07.2004 17:00, Colin Paul Adams wrote:
> I'm trying to do this, but I'm running into real problems.
> The Mozilla javascript console shows nothing.
This is server side javascript, it can not end in Mozilla js console.
> <fb:javascript id="id" path="count(preceding::sibling[local-name() = 'event']) + 1" direction="load">
> <fb:load-form>
> var appValue = java.lang.StrictMath.floor (jxpathPointer.getValue());
> var formValue = new java.lang.Double (appValue);
> var longValue = new java.lang.Long (formValue.longValue());
> widget.setValue (longValue);
> </fb:load-form>
> </fb:javascript>
> Why I don't know
It's wrong. @path refers to "where to get/set the value".
> - nor how to debug it,
That's indeed difficult. Only help is the usage of print().
> but the XPath expression is correct, I think
No. preceding::sibling[local-name() = 'event'] should read
preceding-sibling::*[local-name() = 'event'].
> On the documentation page, the example shows use of a function
> doLoadConversion(),
Don't know about it.
The code should be something like:
<fb:javascript id="id" path="@id" direction="save">
<fb:save-form>
var appValue = jxpathPointer.getValue();
if (appValue == '') {
var precSiblId =
jxpathContext.getValue("../preceding-sibling::contact/@id");
var newId = Number(precSiblId) + 1
jxpathPointer.setValue(newId.toFixed(0));
}
</fb:save-form>
</fb:javascript>
This works for me. I committed it to CVS for the first XML binding sample.
Joerg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: CForms Binding to XML file sample
Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "Joerg" == Joerg Heinicke <jo...@gmx.de> writes:
Joerg> IIRC you can add a <fb:on-bind> on the same level as
Joerg> <fb:on-insert> where you add the logic for id generation
Joerg> via <fb:javascript>.
I'm trying to do this, but I'm running into real problems.
The Mozilla javascript console shows nothing.
The following:
<fb:javascript id="id" path="count(preceding::sibling[local-name() = 'event']) + 1" direction="load">
<fb:load-form>
var appValue = java.lang.StrictMath.floor (jxpathPointer.getValue());
var formValue = new java.lang.Double (appValue);
var longValue = new java.lang.Long (formValue.longValue());
widget.setValue (longValue);
</fb:load-form>
</fb:javascript>
Yields:
"file:/home/colin/onevoice/members/forms/event-binding.xml", line 40:
uncaught JavaScript exception: at events2xml
(file:/home/colin/onevoice/members/flow/binding.js, Line 12) at
(resource://org/apache/cocoon/forms/flow/javascript/Form.js, Line
165): java.lang.ClassCastException
org.apache.avalon.framework.CascadingRuntimeException:
"file:/home/colin/onevoice/members/forms/event-binding.xml", line 40:
uncaught JavaScript exception: at events2xml
(file:/home/colin/onevoice/members/flow/binding.js, Line 12) at
(resource://org/apache/cocoon/forms/flow/javascript/Form.js, Line
165): java.lang.ClassCastException
Why I don't know - nor how to debug it, but the XPath expression is
correct, I think (for the first binding attempt, it yields the string
"1.0").
On the documentation page, the example shows use of a function
doLoadConversion(),
But if I try to use this, I get an error saying there is no such function.
--
Colin Paul Adams
Preston Lancashire
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: CForms Binding to XML file sample
Posted by Joerg Heinicke <jo...@gmx.de>.
On 03.07.2004 10:48, Colin Paul Adams wrote:
> Joerg> I would not see the behaviour of the binding as a problem,
> Joerg> only the result of having not unique ids. I think that was
> Joerg> let out with intent. It's up to you to do it either after
> Joerg> form processing or in the binding itself. There is a
> Joerg> fb:javascript where you can code id generation for
> Joerg> example.
>
> How?
> In:
>
> <fb:on-insert-row>
> <!-- The insert-node element contains a piece of template XML to be
> inserted for new rows. Alternatively, you could also add a "src"
> attribute on the insert-node element pointing to an external source
> to retrieve the template from. -->
> <fb:insert-node>
> <!-- template inserted by the binding for new rows (mapping new nodes) -->
> <event xmlns="http://colina.demon.co.uk/onevoice/events" id="" date="" time="" finish-at="" suppress-recurring="">
> <title/><location/>
> </event>
> </fb:insert-node>
> </fb:on-insert-row>
>
> I can't code an fb:javascript element as the value of the id
> attribute.
> So where does it fit in?
IIRC you can add a <fb:on-bind> on the same level as <fb:on-insert>
where you add the logic for id generation via <fb:javascript>. This
means <fb:on-insert-row> only adds the nodes, while <fb:on-bind> sets
the values. form2_bind_xml.xml seems to prove my recall:
<fb:repeater id="contacts">
<fb:on-bind>
<!-- executed on updates AND right after the insert -->
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>^^^^^^^^^^^^^^^^^^^^^^^^^^
<fb:value id="phone" path="phone/@nr" />
>>> mapping for phone/@nr ^^^^^^^^^^^^^^^^^^^^
</fb:on-bind>
<fb:on-insert-row>
<fb:insert-node>
<contact id="" row-state="new">
<firstname/><lastname/><phone nr=""/><email/>
>>> empty phone/@nr >>>>>>>>>>>>>^^^^^^^^^^^^^^
</contact>
</fb:insert-node>
</fb:on-insert-row>
</fb:repeater>
Joerg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: CForms Binding to XML file sample
Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "Joerg" == Joerg Heinicke <jo...@gmx.de> writes:
Joerg> I would not see the behaviour of the binding as a problem,
Joerg> only the result of having not unique ids. I think that was
Joerg> let out with intent. It's up to you to do it either after
Joerg> form processing or in the binding itself. There is a
Joerg> fb:javascript where you can code id generation for
Joerg> example.
How?
In:
<fb:on-insert-row>
<!-- The insert-node element contains a piece of template XML to be
inserted for new rows. Alternatively, you could also add a "src"
attribute on the insert-node element pointing to an external source
to retrieve the template from. -->
<fb:insert-node>
<!-- template inserted by the binding for new rows (mapping new nodes) -->
<event xmlns="http://colina.demon.co.uk/onevoice/events" id="" date="" time="" finish-at="" suppress-recurring="">
<title/><location/>
</event>
</fb:insert-node>
</fb:on-insert-row>
I can't code an fb:javascript element as the value of the id
attribute.
So where does it fit in?
--
Colin Paul Adams
Preston Lancashire
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: CForms Binding to XML file sample
Posted by Joerg Heinicke <jo...@gmx.de>.
On 02.07.2004 11:31, Colin Paul Adams wrote:
> It seems to me there is something seriously wrong with the binding to
> xml file sample.
>
> If I add a new row to the table at the bottom, I get the following XML
> output:
...
> Note that the id field for the new row is an empty attribute.
>
> This is no good - if the repeater widget requires unique ids (and note
> that these if attributes are not of type ID or xs:ID as they do not
> begin with a letter, but that's another issue), then why is there not
> an id assigned to the new row?
>
> If two rows were added, immediately the ids would no longer be
> unique.
> And if this data file were read in again, there would be a problem.
I would not see the behaviour of the binding as a problem, only the
result of having not unique ids. I think that was let out with intent.
It's up to you to do it either after form processing or in the binding
itself. There is a fb:javascript where you can code id generation for
example. Everything else (i.e. adding the functionality in what way ever
to cforms) would be an enhancement IMO.
Joerg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org