Stewart, Gary wrote:
Hi people,

I'm using CForms in Cocoon 2.1.8 and I've run into a bit of a problem
(I sort of posted about this a while back so a bit of this is a
repost). I was trying to feed some HTML into the form to provide
output to the user. To do this I use a pipe that generates XML output
and then I try and serialize that into the document using the JX
template stuff that looks like:

<jx:set var="xhtmlString"
value='${widget.getChild("op-list").getValue()}' /> <jx:out
value="${Packages.org.apache.cocoon.xml.StringXMLizable(xhtmlString)}"
/>

Unfortunately that doesn't dynamically regenerate when the op-list
value has changed (if anyone knows how to make it do that under AJAX
that would be the best solution by far).

You should be able to get the AJAX framework to update that snippet of code by wrapping it in a bu:replace element when it needs to be updated. Anything that is wrapped in a bu:replace will be sent to the browser in the AJAX response and updated in the page.

<jx:set var="xhtml">
  <div id="op-list-xhtml">
    <jx:set var="xhtmlString"
value='${widget.getChild("op-list").getValue()}' />
<jx:out value="${Packages.org.apache.cocoon.xml.StringXMLizable(xhtmlString)}"/>
  </div>
</jx:set>
<jx:choose>
  <jx:when test="${cocoon.request.getParameter('cocoon-ajax') != null}">
    <bu:replace id="op-list-xhtml"
            xmlns:bu="http://apache.org/cocoon/browser-update/1.0";>
      ${xhtml}
    </bu:replace>
  </jx:when>
  <jx:otherwise>${xhtml}</jx:otherwise>
</jx:choose>

That's untested but should be along the lines of what you need. Notice the <div> with the identical id attribute as the only child of bu:replace - this is the element that will be inserted into the page, and its id marks it as the target for future updates.

You'll also probably want to add logic to only add the bu:replace when the widget's value has been udpated. Since you're already importing the CForms jx-macros file you'll have access to the 'cformsHelper' variable which is a helper class that has some tools for this sort of thing.

Hope that helps
--Jason



If I go for a straight up output then I just get the
<div><p>Moo</p></div> tags displayed. I looked at serialization on
the forms-field-styling.xsl, as XSLT 1.0, and therefore Xalan (AFAIK)
doesn't have a serialize function I looked at creating one that
looked something like this:

<!--This is an extension script to add serialization as a function-->
<xalan:component prefix="custom" functions="serialize"> <xalan:script lang="javascript"> function serialize(xmlString) { var output = Packages.org.apache.cocoon.xml.StringXMLizable(xmlString); if(output == null) { output = "Oh Dear"; } return output; } </xalan:script> </xalan:component>

but that just generated NULL values so I gave up on that.

I even wrote a stylesheet to convert the HTML into Text and just use
output but IE seems to ignore the line breaks on the <pre /> tag when
you insert it in dynamically (damn IE).

Any ideas on how to get the AJAX stuff to display this dynamically
when the value changes?

Thanks,

Gary

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to