javascript - f:ajax onerror called before listener - Stack Overflow

I have a simple form and a pretty simple bean that listens to an ajax event. Here is some of the code:&

I have a simple form and a pretty simple bean that listens to an ajax event. Here is some of the code:

<script type="text/javascript">
    function myfunction() {
         alert('error');
    }
</script>
<h:mandButton  id="someid" value="somevalue" >
   <f:ajax event="click" execute="someids" listener="#{MyBean.fireEvent}" onerror="myfunction()"  />    
</h:mandButton>

I am using eclipse in debug to see when MyBean.fireEvent is getting called and as far as I can tell it is getting called after onerror="myfunction()" is executed. What could be the reason for that?

I am using mojarra 2.0 with Resin.

Thanks.

I have a simple form and a pretty simple bean that listens to an ajax event. Here is some of the code:

<script type="text/javascript">
    function myfunction() {
         alert('error');
    }
</script>
<h:mandButton  id="someid" value="somevalue" >
   <f:ajax event="click" execute="someids" listener="#{MyBean.fireEvent}" onerror="myfunction()"  />    
</h:mandButton>

I am using eclipse in debug to see when MyBean.fireEvent is getting called and as far as I can tell it is getting called after onerror="myfunction()" is executed. What could be the reason for that?

I am using mojarra 2.0 with Resin.

Thanks.

Share Improve this question edited Nov 28, 2012 at 18:51 BalusC 1.1m376 gold badges3.7k silver badges3.6k bronze badges asked Jul 5, 2012 at 19:13 casolorzcasolorz 9,66422 gold badges107 silver badges219 bronze badges 1
  • Figured out how to get it to work. Above the myfunction() definition I added jsf.ajax.addOnError(myfunction); and removed the onerror="myfunction()" attribute from the ajax tag. I am still curious as to why the onerror attribute didn't work though. – casolorz Commented Jul 5, 2012 at 19:30
Add a ment  | 

2 Answers 2

Reset to default 5

looks like a formatting problem, maybe try:

<script type="text/javascript">
  function myfunction(error) {
     alert(error.description);
  }
</script>

<h:mandButton  id="someid" value="somevalue" >
  <f:ajax event="click" 
       execute="someids" 
       listener="#{MyBean.fireEvent}" 
       onerror="myfunction" />    
</h:mandButton>

The onerror attribute must point to the function name itself, not to the return value of the function.

So, if you replace

onerror="myfunction()" 

by

onerror="myfunction" 

then it should work as expected.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745141113a4613435.html

相关推荐

  • javascript - f:ajax onerror called before listener - Stack Overflow

    I have a simple form and a pretty simple bean that listens to an ajax event. Here is some of the code:&

    1小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信