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

2

5

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.

Waftage answered 21/10, 2011 at 16:1 Comment(0)
W
8

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>
Waftage answered 24/10, 2011 at 22:48 Comment(0)
P
0

You would need to call oncomplete on the component that fires the Ajax request. a4j:outputPanel doesn't have oncomplete attribute.

Pebbly answered 21/10, 2011 at 17:50 Comment(1)
right, I understand that outputPanel doesn't have an oncomplete attribute. There are way too many components to manage oncomplete on all of them. I'm looking to listen for the event globally.Waftage

© 2022 - 2024 — McMap. All rights reserved.