Duncan McLean wrote:
Thanks very much for your detailed advice!
Hope it will help ! Do not hesitate to post back if you notice some wrong information.

Patrick


Duncan

Patrick Refondini wrote:

Duncan McLean wrote:

Hi Patrick

Thanks for this...

Not too sure what you mean by uniqueAttributeNameConstraint(event) - can
you explain a bit further please?


Yes, the uniqueAttributeNameConstraint(event) is totally specific to one of my use case I simply "cut and pasted", not very generic indeed.

Thus more generically:

fd:on-value-changed let you add event listeners on widgets instances.

You can add Java or / and Javascript event listeners. To learn more about it you may have a look to: http://cocoon.apache.org/2.1/userdocs/widgetconcepts/eventhandling.html

Now to get you on feet for a quick test if you like you may:

1. Add attach a flowscript file to your sitemap.xmap:

  <!-- indicates what flowscript to attach to this sitemap -->
  <map:flow language="javascript">
    <map:script src="yourPathToYourFlowScripts/my_events_flow.js"/>
  </map:flow>

2. Create a basic event listener in my_events_flow.js

/*
* Copyright ...
*/
cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js");

/**
 * A simple test function
 */
function eventPrint(event) {
  print("");     print(">>>> eventPrint(event) v1.0 <<<<<");
  var sourceWidget = event.source;
  print("sourceWidget = " + sourceWidget);
  print("");
}


3. Make use of the event listener in one of your CFlow model

<fd:field id="yourFieldName">
  <fd:datatype base="string"/>
     <fd:on-value-changed>
       <fd:javascript>
         eventPrint(event);
       </fd:javascript>
     </fd:on-value-changed>
</fd:field>


That should be about it.

Now when yourFieldName value changes you should be able to see some >>>> eventPrint(event) v1.0 <<<<< output in your logs. print() will log on the standard output. In container such as Tomcat it appears in logs/catalina.out. Should be on your console if you launch cocoon in the command line using jetty.

From there you have all the power of the flow backend. You are able to call logic on Java classes, resources, may certainly use pipelineUtil .... You can also update other form fields/widgets values... Especially nice while working with AJAX, just my opinion though ;)

You should have access to:

event.oldValue
event.newValue

You may find about other fields/widgets using:

event.source.lookupWidget("../anotherFieldId")

You may also experiment with

event.source.value
event.source.parent

In your field auditing value change is contained in a repeater's row:

var row = event.source.parent;
var repeater = row.parent;
var pos = repeater.indexOf(row);

for (var i = 0; i < repeater.size; i++) {
  var currentRow = repeater.getRow(i);
}

... just a few hints

Patrick


Thanks

Duncan


Hi Duncan,

If onChange can be used instead of onBlur in your senario you might be
able to use something as follow in you CForm model (fd):

<fd:field id="name">
  <fd:datatype base="string"/>
    <fd:on-value-changed>
      <fd:javascript>
      uniqueAttributeNameConstraint(event);
      </fd:javascript>
    </fd:on-value-changed>
</fd:field>

I have used this with Cocoon 2.1.8 with AJAX block enabled, and of
course AJAX enabled in the form template too:

<ft:form-template
  action="#{$cocoon/continuation/id}.continue"
  method="POST"
  ajax="true">


Patrick


Duncan McLean wrote:

Hi

We have a rather complicated scenario where we would like to effectively call a business service which does some detailed calculations involving a value from a text field on a form and then updating the same form with
the value.

Effectively, the users would like the service calculation to trigger
after an onBlur event on the affected text field.

We already call a business service in flow (using and XSP page which
composes the required SOAP request). We then call this pipeline within
flow which causes the business service to be called and we can then get at the returned DOM to extract the values. This can be done up front in flow which makes this scenario easy, but the onBlur scenario is proving
trickier.

What would be nice would be to (in the fd:javascript block for the text box) using a similar method to the above - call a pipeline that creates another XSP page that will create the appropriate SOAP request and call
the business service, interrogate the results and incorporate the
results into the same form! Tricky?

Sorry that this sounds a bit convoluted, but does anyone have a better
suggestion on how to achieve this?

So, in summary - onBlur called against a text field, results in creation
of SOAP request to a business service which does some business logic
calcs, returns some XML which is interrogated for a value and area on
the same form re-populated with result of calculation.

Phew

Thanks in advance

Duncan


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



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







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



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







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



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

Reply via email to