JSF在f:ajax之后执行javascript。

时间:2021-12-24 20:04:57

In my JSF 2 web application, I use the following code to display and switch the contents of a rich:dataTable according to the selectedStatus:

在我的JSF 2 web应用程序中,我使用以下代码显示和切换一个rich:dataTable,根据selectedStatus:

<h:selectOneRadio id="statusSelection" value="#{backingBean.selectedStatus}" style="width:auto; float:left;">
  <f:selectItem itemValue="AVAILABLE" itemLabel="Available" />
  <f:selectItem itemValue="INACTIVE" itemLabel="Inactive" />
  <f:ajax render="itemsDataTable" execute="#{backingBean.sortByTitel('ascending')}" />
  <f:ajax render="itemsDataTable" event="click" />
</h:selectOneRadio>

The dataTable contains a4j:commandLink s, which unintentionally need to be double clicked in some IE versions after changing table content - I found out, that executing the following Javascript code (on IE's debugging console, after table contents have changed) solves the issue:

dataTable包含a4j:commandLink s,在更改表内容后,在某些IE版本中无意中需要双击——我发现,执行以下Javascript代码(在IE的调试控制台,在表内容更改后)可以解决这个问题:

document.getElementById(<dataTableClientId>).focus()

My question is: How can I achieve automatic execution of the javascript code after the table contents have changed?

我的问题是:如何在表内容更改后自动执行javascript代码?

1 个解决方案

#1


21  

In order to call a js code after the f:ajax the following inline solution will do

为了在f:ajax之后调用js代码,下面的内联解决方案就可以了

<f:ajax render="itemsDataTable" 
    onevent="function(data) { if (data.status === 'success') { 
    document.getElementById('dataTableClientId').focus() } }"/>

also take a look at this answer: JSF and Jquery AJAX - How can I make them work together?

还要看一下这个答案:JSF和Jquery AJAX——我如何使它们协同工作?

Also, double check the need of the event="click" in your f:ajax , cause the default event in h:selectOneRadio is change which I think you better use...

另外,双击您的f:ajax中的event="click",因为h:selectOneRadio中的默认事件是更改,我认为您最好使用……

#1


21  

In order to call a js code after the f:ajax the following inline solution will do

为了在f:ajax之后调用js代码,下面的内联解决方案就可以了

<f:ajax render="itemsDataTable" 
    onevent="function(data) { if (data.status === 'success') { 
    document.getElementById('dataTableClientId').focus() } }"/>

also take a look at this answer: JSF and Jquery AJAX - How can I make them work together?

还要看一下这个答案:JSF和Jquery AJAX——我如何使它们协同工作?

Also, double check the need of the event="click" in your f:ajax , cause the default event in h:selectOneRadio is change which I think you better use...

另外,双击您的f:ajax中的event="click",因为h:selectOneRadio中的默认事件是更改,我认为您最好使用……