0 Replies Latest reply on Apr 8, 2013 12:28 PM by Feki Ahmed

    Is it possible to use JS generated code by <a4j:jsFunction>  directly ?

    Feki Ahmed Newbie



      In the Practical Richfaces Apress book 2nd edition , it s written that "Without <a4j:jsFunction> we would have to type something similar by hand." when talking about the JS code generated by that Richfaces tag.


      So, for this piece of code in my xhtml page :


      <script type="text/javascript">



















      <h:form id="form1">


         <div id="mondiv" style="background-color:red;position:absolute;width:20px;height:20px;"/>

         <a4j:jsFunction name="doAwesomeness" action="#{bean.awesomeMethod}"/>  





      I got in the source code of the generated page this code :



      <form id="form1" name="form1" method="post" action="/Ajax4JsfAppTest/index.xhtml" enctype="application/x-www-form-urlencoded">

      <input type="hidden" name="form1" value="form1" />



         <div id="mondiv" style="background-color:red;position:absolute;width:20px;height:20px;"></div>

      <span id="form1:j_idt8" style="display: none;"><script type="text/javascript">doAwesomeness=function(){RichFaces.ajax("form1:j_idt8",null,{"incId":"1"} )};</script></span><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="151578633821379875:5260082206524838524" autocomplete="off" />



      So i re-wrote my html page like this :




      <h:form id="form1">


         <div id="mondiv" style="background-color:red;position:absolute;width:20px;height:20px;"/>


         <span id="myspan" style="display: none;"><script type="text/javascript">doAwesomeness=function(){RichFaces.ajax("myspan",null,{"incId":"1"} )};</script></span>




      I've tried it but i got the JS error saying that "Richfaces is not defined" triggered for the RichFaces.ajax method


      [17:45:21,506] ReferenceError: RichFaces is not defined @ http://localhost:8080/Ajax4JsfAppTest/:31


      And anyway it won't work as the method bean.awesomeMethod binded in the action attribute of the a4j:jsFunction isn't mentionned.



      Actually, what i need to know is if i can programmatically trigger a managed bean method only with JS. And i would like also to know if i can programmatically add the a4j:jsFunction by java code to the view (does any UIComponent like HtmljsFunction exists ?)


      Best Regards!