I want to execute something in backend, when the data-attribute of a ZK element changes.
There's a MutationObserver
in Javascript, is there something similar in ZK that I can use?
I already checked the ZK Events
class but there doesn't seem to be an event that listens to attribute changes.
There is no event listener or similar by default that would be triggered when changing a clientAttribute on a component.
Where does the change originate from? Is it an event happening at client-side? Or a change done on the component object in Java? Could you explain the use case? there might be a different way to achieve it :)
Edit: technical solution after exchanges. firing an event from client to server side: https://www.zkoss.org/wiki/ZK_Client-side_Reference/Communication/AU_Requests/Client-side_Firing#Fire_Event_Directly_to_Server
I'd recommend firing a "onCustom"
event instead (any event name starting by "on"+yourEventName
). You will also need to use toServer:true
in the event optional arguments to have it fired to the server directly. this one is a good option: zAu.send(new zk.Event(wgt, "onFoo", {foo: 'my data'}, {toServer:true}));
where wgt
is the widget object, "onFoo"
is the custom event name, {foo: 'my data'}
is the payload, if you need to send anything back to the server, and {toServer: true}
is the optional arguments, with the toServer entry
the issue with firing onChange
is that is is a default event sent by default actions. there is already behaviors tied to onChange
on most components. you might trigger a default workflow which expects a specific payload and create an error situation. By sending a onCustomName
(whathever it is, just not a default event) event, you are sure to only trigger the listener in by invoking the zAu.send