通过a4j:jsFunction调用原生的javascript的方法,并且共享和传递后台beann里面的变量;

 

  1. <ui:compositionxmlns="http://www.w3.org/1999/xhtml"

  2. xmlns:ui="http://java.sun.com/jsf/facelets"

  3. xmlns:h="http://java.sun.com/jsf/html"

  4. xmlns:f="http://java.sun.com/jsf/core"

  5. xmlns:a4j="http://richfaces.org/a4j"

  6. xmlns:rich="http://richfaces.org/rich">

  7. <mce:scripttype="text/javascript"><!--  

  8.   function showContent(data)  

  9.   {  

  10.       alert(data);  

  11.   }  

  12. // --></mce:script>

  13. <tablewidth="400">

  14. <tbody>

  15. <tr>

  16. <td><spanonmouseover="updateName('Kate')"onmouseout="updateName('')">Kate</span></td>

  17. <td><spanonmouseover="updateName('John')"onmouseout="updateName('')">John</span></td>

  18. <td><spanonmouseover="updateName('Alex')"onmouseout="updateName('')">Alex</span></td>

  19. </tr>

  20. <rich:spacerheight="10"/>

  21. <tr>

  22. <tdcolspan="3">Name: <b><h:outputTextid="showname"value="#{detailQueryBean.selectedRange}"/></b></td>

  23. </tr>

  24. </tbody>

  25. </table>

  26. <a4j:form>

  27. <a4j:jsFunctionname="updateName"reRender="showname"oncomplete="javascript:showContent('#{detailQueryBean.selectedRange}');">

  28. <a4j:actionparamname="param1"assignTo="#{detailQueryBean.selectedRange}"/>

  29. </a4j:jsFunction>

  30. </a4j:form>

  31. <br/>

  32. </ui:composition>

  1. <a4j:form>

  2. <a4j:jsFunctionname="callScript"

  3. oncomplete="javascript:showContent('爱上地方');"/>

  4. </a4j:form>