Friday, June 22, 2012

simulate a4j:jsFunction in richfaces

a4j:jsFunction is very useful. It defines a javascript function you can make ajax call through script by invoking this function. How can you do the same thing without richfaces library?

First, define your action in a hidden command or inputtext field.

<h:commandButton id="mybutton" styleClass="myclass" style="display:none;" ...>
<f:ajax ...></f:ajax>
</h:commandButton>


javascript in YUI

myfunction =function()
{
  Y.one("input.myclass").simulate("click");
}

javascript in jQuery
myfucntion=function()
{
 jQuery("input.myclass").trigger("click");
}

After this you can use myfunction anywhere to trigger the ajax behavior.
 

No comments:

Post a Comment