2

Orbeon version: Orbeon Forms 3.8.0.201005270113

I have the following code in a Javascript file. This code is executed, but it seems like the model in the XBL is not found.

ORBEON.xforms.Document.dispatchEvent("model-name", "event-name");

Here is the model in the XBL. There are several models in the XBL. I don't see any message, so it seems as though the model isn't found. I don't see any errors in the logs.

<xforms:model id="model-name" xxforms:external-events="event-name">
  <xforms:action ev:event="event-name">
    <xforms:message>Test</xforms:message>
  </xforms:action>
</xforms:model>

Does anyone know if there is some trick to getting a dispatch to work from Javascript to XBL?

Thanks very much!

UPDATED:

Another thing that could be the problem (maybe?) is that calling the javascript from the XBL using instance(this) isn't working. I wonder if the instance of the class isn't tied to a component instance, therefore it can't find the model?

Here's the call to the javascript from the xbl that doesn't invoke the init method:

<xxforms:script>YAHOO.xbl.fr.myTest.instance(this).init();</xxforms:script>

Here's the call that does invoke the init() method:

<xxforms:script>YAHOO.xbl.fr.myTest.prototype.init();</xxforms:script>

Here's the javascript:

YAHOO.namespace("xbl.fr");
YAHOO.xbl.fr.myTest = function() {};
ORBEON.xforms.XBL.declareClass(YAHOO.xbl.fr.myTest, "xbl-fr-myTest");

YAHOO.xbl.fr.myTest.prototype = {
},

init: function() {
    alert('test');
},

valueChanged: function() {
},

};
mstrom
  • 1,655
  • 3
  • 26
  • 41

1 Answers1

1

AFAIK you can't address the XBL-internal model directly from outside, because of its strong encapsulation.

Instead, you'll have to dispatch the event to the xbl component node. For example, if you want an instance of the fr:currency XBL to handle a certain event, you'll have to dispatch the event to that fr:currency element that's part of your XForm.

Inside the XBL, you can define xbl:handlers to act upon that event, triggering some JavaScript action or something else.

tohuwawohu
  • 13,268
  • 4
  • 42
  • 61
  • @mstrom: Hope it works! If it does, feel free to accept the answer ;) (if it doesn't work, please report any errors) – tohuwawohu Oct 20 '11 at 08:20
  • @mstrom is right; from JavaScript, you need to target a control in XBL when sending an event. Think of it this way: since you can have multiple instances of that component in your page, when you say "send event `my-event` to `my-model`", when the server gets that information, it can't know which instance of `my-model` you're talking about. Instead, if you send an event to a control, you'll be getting that control from the DOM, and use its id. That id will have all the information needed by the XForms engine to know which instance of the XBL component you're talking about. – avernet Oct 24 '11 at 17:43