0

I've a project which is has created by JSF and dojo. In my main.js I have a function which is doing some stuff like:

define(
    ["./util/Query", "dojo/domReady!" ],
    function(Query) {
        // ... some extra stuff here

        var queryFunctions = new Query(someVar);

        // some extra stuff ...
});

I've also created a module which is named Query :

define(["dojo/_base/declare"],
    function(declare) {
        return declare(null, {
            _someVar: null,

            constructor: function(SomeVar) {
                this._someVar = SomeVar;
            },
            functionOne: function(xhr, status, args) {
                // some stuff here;
            }
        });
});

And in my JSF file, I've a ajax tag to make an ajax request to bean function and then, update a dom object:

<p:ajax update="someDOM"
    listener="#{myBean.changeHandler}"
    oncomplete="functionOne(xhr, status, args)" />

Basically I want to use functionOne() function which is in my Query module. I can not access queryFunctions variable directly in the ajax tag. How can I do that?

Maozturk
  • 339
  • 1
  • 5
  • 20

1 Answers1

1

Event handling through DOM is kind of limiting. You could globally scope queryFunctions so that you can access it from the DOM, however, global variables are considered a bad practice and you should try to use them as less as possible. In this case you might consider doing it (if there's no other way around).

A better way would be to handle your oncomplete event in JavaScript, but I have no idea how that's going to happen (not familiar with JSF).

Community
  • 1
  • 1
g00glen00b
  • 41,995
  • 13
  • 95
  • 133