سؤال

I want to call an function in my jsp pages every time the page is successfully loaded via Ajax call. Consider below:

|Main.jsp--------------------------------------|
|         Link A    Link B    Link C           |
|                                              |
|         -<div id="content">----------        |
|         |                           |        |
|         |                           |        |
|         |                           |        |
|         |                           |        |
|         ----------------------</div>-        |
|                                              |
|----------------------------------------------|

Each of the links will invoke LinkA.jsp, LinkB.jsp and LinkC.jsp And the links are as below:

<sj:a href="%{urlA}" targets="content">LinkA</sj:a>
<sj:a href="%{UrlB}" targets="content">LinkB</sj:a>

There are common javascript functions which must be called when the jsp files are loaded. I can write these general files in an initial.js and add it to all jsp pages.

<script type="text/javascript" src="<s:url value="initial.js" />"></script>

All the jsp files contains a form and I want to manipulate a common function on all inputs some thing like below:

$( document ).ready(function() {
   $("input").changeEncodingInput();
}); 

If I add this code in Main.jsp, the changeEncodingInput will not apply when I load LinkB.jsp and LinkC.jsp

But I think there must be better way.

I am looking for a adding the initial.js file to Main.jsp and do not repeat it in every page.

It seems that the struts 2 jquery plugin internally manage the Ajax events. May be topics are published internally and we can subscribe to it?

Any ideas?!

هل كانت مفيدة؟

المحلول

After some reviews I found the best solution could be achived by adding below to the main.jsp. I hoped that the framework published an event but I could not find any, hope the framework will support that later!

$(document).ajaxStop(function() {
    $("input[lang='fa']").changeEncodingInput();
});

Thanks to @Aleksandr for comments !

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top