In the struts 2 jQuery plugin there is a publish/subscribe framework which can be used for event invocation.
Consider this sample....
One can change the grid behavior when grid is loaded by subscribing too onGridCompleteTopics
event
<sjg:grid id="gridtable" dataType="json"
href="%{url}" gridModel="gridModel" direction="%{pageDir}" width="800"
shrinkToFit="true" onGridCompleteTopics="grid_compelete">
And then in the js:
$.subscribe('grid_compelete', function(event, data) {
//do some thing
}
The problem is that, as above js and the grid are in the same page (they are in one jsp), every time I reload the page the subscribe
is called and the code in the subscribe runs again.
How can I prevent it?! I found a function in jquery.subscribe.1.2.3
which is called isSubscribed
I thought the framework should use it internally to avoid this issue. But it is not!
Also I did not find any way to call and use this method.
Just use return false; at the end of function.
A solution was found at Struts 2 jQuery plugin isSubscribe not working
One can use
or kill the topic (which I do not prefer it myself)
The isSubscibe is still there and it is attached to document, please see Struts 2 jQuery plugin isSubscribe not working for complete code by @Roman C
I had the same issue for onEditInlineSuccessTopics and replacing
with
was the best solution that worked for me.
The other version related to destroyTopic, made the topic work only the first time I edited a row and if I wanted to edit another row, the topic was not called at all.
Of course, that's the standard behavior. If you need something to be ran only once, in the entire life-cycle, you can use session/cookies.
onGridCompleteTopics
- This means everytime the grid loads the topic is published. And everytime the page is reloaded/refreshed the grid is loaded, publishing the event.Hope so it clears your doubt.