如何在 JSF 1.2/Richfaces 3.3 中的渲染中调用 Javascript 函数?
我们有一个 a4j:outputPanel
,它是 ajaxRendered
。有没有办法在每次(重新)渲染时调用 JavaScript 函数?我知道我们可以在每个可能用 oncomplete
提交的元素中调用,但这实际上是不可维护的。
详细信息:
- JSF 1.2
- Richfaces 3.3
示例(oncomplete 在 outputPanel 标记上实际上不可用):
<a4j:outputPanel ajaxRendered="true" oncomplete="myJSFunc()">
<h:outputText value="Test-aroo" />
</a4j:outputPanel>
<!-- other inputs, buttons and stuff -->
更新 jQuery 库是否能够提供帮助(它内置于 RichFaces 中)?我正在考虑使用 .live() 来注册 oncomplete 事件。我将继续尝试并根据进展进行更新。
更新 我没有机会实现 jQuery 解决方案,但正如我的答案所示,myJSFunc()
可以直接放在渲染的标签内。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案是将 javascript 放在 outputPanel 内的 script 标记中:
A solution is to put the javascript in a script tag inside the outputPanel:
您需要在触发 Ajax 请求的组件上调用 oncomplete。 a4j:outputPanel 没有 oncomplete 属性。
You would need to call oncomplete on the component that fires the Ajax request. a4j:outputPanel doesn't have oncomplete attribute.