using A4J, how do I rerender a javascript function, and call it after rerendering?

天大地大妈咪最大 提交于 2019-12-11 07:49:50

问题


for example, I've tried

<a4j:region id="scriptSuggested" >
<f:verbatim>
<script>
  reallyUpdateIt = function () {
       // javascript code that changes after aj4 ajax call is triggered
      }
    </script>
   </f:verbatim>
    <a4j:jsFunction reRender="scriptSuggested" ignoreDupResponses="true" ajaxSingle="true" name="updateSuggestionValues" action="#{bean.action}" oncomplete="reallyUpdateIt();">
        <a4j:actionparam name="userInput" assignTo="#{bean.input}" />
    </a4j:jsFunction>
</a4j:region>

I would expect that calling the javascript function

updateSuggestionValues('val');

is going to do the action

#{bean.action}

and after that it would rerender the region scriptSuggested and finally would call reallyUpdateIt() ,

all works except the part of updating the code of reallyUpdateIt(), I checked the ajax response using firebug, and it comes with the expected new javascript code, but when I call reallyUpdateIt() , the old code is triggered.

I am using JSF 1.2, richfaces 3.3.3,


回答1:


it turns out using <a4j:region id="scriptSuggested" > doesn't generate an html section that A4J can rerender, I had to use <a4j:outputPanel> , so now it updates the function, my code now looks like :

<a4j:region >
<a4j:outputPanel id="scriptSuggested">  
<f:verbatim>
<script>
  reallyUpdateIt = function () {
       // javascript code that changes after aj4 ajax call is triggered
      }
    </script>
   </f:verbatim>
    <a4j:jsFunction reRender="scriptSuggested" ignoreDupResponses="true" ajaxSingle="true" name="updateSuggestionValues" action="#{bean.action}" oncomplete="reallyUpdateIt();">
        <a4j:actionparam name="userInput" assignTo="#{bean.input}" />
    </a4j:jsFunction>
</a4j:outputPanel>
</a4j:region>


来源:https://stackoverflow.com/questions/18858942/using-a4j-how-do-i-rerender-a-javascript-function-and-call-it-after-rerenderin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!