FBRD
FBRD

Reputation: 63

Reinitialize jsf custom component after ajax update

I have a custom component based on JavaScript to initialize it after DOM complete. but when I update the component by an Ajax call, it will be updated but it never initialized..

I read some code of primeFaces and omniFaces but it seems not very simple to do that.

What is the best way to call the JavaScript code to reinitialize the component after every Ajax update.

edit:

Suppose i want to transform a jQuery Plugin (like select2) to jsf custom component, and i want to call the jQuery method $('#myComponentId').select2() after every ajax update

this is what i need

thanks in advance.

Upvotes: 2

Views: 899

Answers (1)

FBRD
FBRD

Reputation: 63

I solve the problem by rendering a JavaScript after the component to reinitialize it..

Exmaple:

<div id="myComponent" name="myComponent">
   ...
   <script type="text/javascript">
      $("#myComponent").select2();
   </script>
</div>

and when the component updated after an Ajax call, the JavaScript will execute automatically

Upvotes: 2

Related Questions