Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a Javascript function on render in JSF 1.2/Richfaces 3.3?

We have an a4j:outputPanel that is ajaxRendered. Is there a way to call a javascript function each time it is (re)rendered? I know that we could put a call in every element that could possibly submit with oncomplete, but that really isn't practicably maintainable.

Details:

  • JSF 1.2
  • Richfaces 3.3

Example (oncomplete isn't actually available on the outputPanel tag):

<a4j:outputPanel ajaxRendered="true" oncomplete="myJSFunc()">
    <h:outputText value="Test-aroo" />
</a4j:outputPanel>
<!-- other inputs, buttons and stuff -->

Update Might the jQuery library be able to help (it's built into RichFaces)? I'm looking at using .live() to maybe register with the oncomplete event. I'll keep experimenting and update with progress.

Update I didn't get a chance to implement the jQuery solution, but as my answer shows below myJSFunc() can just be put directly inside the rendered tags.

like image 716
Adam Avatar asked Oct 21 '11 16:10

Adam


1 Answers

A solution is to put the javascript in a script tag inside the outputPanel:

<a4j:outputPanel ajaxRendered="true">
    <h:outputText value="Test-aroo" />
    <script type="text/javascript">myJSFunc();</script>
</a4j:outputPanel>
like image 173
Adam Avatar answered Sep 22 '22 12:09

Adam