You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by trondal <tr...@stud.ntnu.no> on 2005/06/22 15:58:48 UTC

Cforms:Binding to specific element and saving

I want to bind to just <user id="1"> on the following xml-file:
<users>
	<user id="1">
		<name>Johan</name>
	</user>
	<user id="2">
		<name>Mark</name>
	</user>
</user>

Here are the sitemap whitch does the job:

<map:match pattern="modify_course">
       <map:call function="handleForm">
         <map:parameter name="function" value="{0}"/>
         <map:parameter name="form-definition"
value="modify_course_definition.xml"/>
         <map:parameter name="documentURI"
value="xmldb:exist:///quis/courses/courses.xml#/users/user[@id='1']"/>	
	   <map:parameter name="bindingURI"
value="modify_course_binding.xml"/>
    </map:call>
</map:match> 

All works well until i save: "Cannot modify a resource that includes an
XPATH expression".
Previos samples-examples with bindings have worked well, but they all work
on a easily identifiable path.
How can I use Xpath to identify the element, and still save the modified
part?  


Can anybody please point me in the right direction on how to overcome this?


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Cforms:Binding to specific element and saving

Posted by Ben Pope <be...@gmail.com>.
trondal wrote:
> I want to bind to just <user id="1"> on the following xml-file:
> <users>
> 	<user id="1">
> 		<name>Johan</name>
> 	</user>
> 	<user id="2">
> 		<name>Mark</name>
> 	</user>
> </user>
> 
> Here are the sitemap whitch does the job:
> 
> <map:match pattern="modify_course">
>        <map:call function="handleForm">
>          <map:parameter name="function" value="{0}"/>
>          <map:parameter name="form-definition"
> value="modify_course_definition.xml"/>
>          <map:parameter name="documentURI"
> value="xmldb:exist:///quis/courses/courses.xml#/users/user[@id='1']"/>	
> 	   <map:parameter name="bindingURI"
> value="modify_course_binding.xml"/>
>     </map:call>
> </map:match> 
> 
> All works well until i save: "Cannot modify a resource that includes an
> XPATH expression".
> Previos samples-examples with bindings have worked well, but they all work
> on a easily identifiable path.
> How can I use Xpath to identify the element, and still save the modified
> part?  
> 
> 
> Can anybody please point me in the right direction on how to overcome this?

Hmm, if you used repeaters you could specify something like the following in your binding:

<fb:repeater id="users" parent-path="/users" row-path="/user[@id='1']" row-path-insert="/user">

Of course, your documentURI would have to change to smething more like:
  value="xmldb:exist:///quis/courses/courses.xml

Perhaps that helps?  I doubt you would want to allow them to change the id.

Ben

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Cocoon 2.1.6 vs Cocoon 2.1.7

Posted by Daniel McOrmond <dm...@gmail.com>.
Hi Guillaume,

I would recommend using Cocoon 2.1.7. It is the latest stable version.

In regards to JavaFlow, that all depends on your definition of
'stable'.  :)  Some folks are using it in production [1], but I
believe it's still listed as 'unstable' [2].

HTH,

-Daniel


[1] <http://www.mail-archive.com/dev@cocoon.apache.org/msg31922.html>
[2] <http://www.mail-archive.com/dev@cocoon.apache.org/msg32052.html>



On 6/23/05, Guillaume Helle <gu...@capgemini.com> wrote:
> Hi all,
> 
> i am starting a new Cocoon application and i have the choice between Cocoon
> 2.1.6 and 2.1.7...
> Is Cocoon 2.1.7 stable? Can i use Java Flows with it?
> 
> Best Regards,
> 
> Guillaume Helle

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Cocoon 2.1.6 vs Cocoon 2.1.7

Posted by Guillaume Helle <gu...@capgemini.com>.
Hi all,

i am starting a new Cocoon application and i have the choice between Cocoon
2.1.6 and 2.1.7...
Is Cocoon 2.1.7 stable? Can i use Java Flows with it?

Best Regards,

Guillaume Helle


This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient,  you are not authorized to read, print, retain, copy, disseminate,  distribute, or use this message or any part thereof. If you receive this  message in error, please notify the sender immediately and delete all  copies of this message.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Cforms:Binding to specific element and saving

Posted by Huib Verweij <hu...@streamtec.nl>.
Hi Trondal,

If I understand your message correctly, you are trying to get data from an
xmldb, modify it and write it back. If that's correct, read on...

Getting data out of the xmldb is easy. Getting it back in is a little more
complicated. Not much though. But I got the same errormessage as you at one
stage. It took me some time to come up with a solution. It works but there
may be other, more elegant solutions.

As you say, everything goes well until you want to save your XML back to the
database. My solution is this, in the javascript file you call upon a
sitemap component that injects your data into the pipeline using the JXPath
framework. Then you use xupdate to update your xmldb.

In the javascript file:

    // bind the form's data back to the document
    form.save(document);
    // save the DOM-tree back to XML using the JXPath framework
   cocoon.sendPage("edit-success-pipeline", { "dom":document } );


In the sitemap use this to get your xml back into the pipeline:

    <map:match pattern="edit-success-pipeline">
      <map:generate type="jx" src="resources/jx/edit-success-pipeline.jx">
         <map:parameter name="lenient-xpath" value="true"/>
      </map:generate>
      <map:transform src="update-xmldb.xslt"/>
      <map:transform type="xmldb" />
      .....
      <map:serialize type="html"/>
    </map:match>

The crucial component is the .jx file that generates the data as XML and
inserts it into the pipeline. Once the XML is in the pipeline, use
<map:transform src="update-xmldb.xslt"/> to prepare the xupdate queries and
use <map:transform type="xmldb" /> to execute these queries. Here's the .jx
file:

     <page xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
         <jx:out value="#{dom/*}"/>
    </page>

The update-xmldb.xslt goes like this:

 <xsl:template match="......">
   <x:query type="update" collection="collection" oid="quis">
     <xu:modifications version="1.0">
        <xu:remove select="//courses/courses.xml#/users/user[@id='1']" />
        <xu:insert-before child="1"
select="//quis/courses/courses.xml#/users/*"><xsl:copy-of select="user"
/></xu:insert-before>
     </xu:modifications>
   </x:query>
 </xsl:template>


or something like that, feel free to experiment to get it exactly right ;-).

I'm curious to see if anyone's come up with another solution.

I hope this helps, good luck.

Huib.

----- Original Message ----- 
From: "trondal" <tr...@stud.ntnu.no>
To: <us...@cocoon.apache.org>
Sent: Wednesday, June 22, 2005 6:58 AM
Subject: Cforms:Binding to specific element and saving


>
> I want to bind to just <user id="1"> on the following xml-file:
> <users>
> <user id="1">
> <name>Johan</name>
> </user>
> <user id="2">
> <name>Mark</name>
> </user>
> </user>
>
> Here are the sitemap whitch does the job:
>
> <map:match pattern="modify_course">
>        <map:call function="handleForm">
>          <map:parameter name="function" value="{0}"/>
>          <map:parameter name="form-definition"
> value="modify_course_definition.xml"/>
>          <map:parameter name="documentURI"
> value="xmldb:exist:///quis/courses/courses.xml#/users/user[@id='1']"/>
>    <map:parameter name="bindingURI"
> value="modify_course_binding.xml"/>
>     </map:call>
> </map:match>
>
> All works well until i save: "Cannot modify a resource that includes an
> XPATH expression".
> Previos samples-examples with bindings have worked well, but they all work
> on a easily identifiable path.
> How can I use Xpath to identify the element, and still save the modified
> part?



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org