JSF execute javascript after f: ajax

In my JSF 2 web application, I use the following code to display and switch rich content: dataTable according to the selected status:

<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 inadvertently needs to be double-clicked in some versions of IE after changing the contents of the table - I found out that running the following Javascript (on the IE debugging console after changing the contents of the table) solves the problem:

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

My question is: how can I get javascript code to execute automatically after changing the contents of a table?

+8
javascript ajax jsf
source share
1 answer

To call js code after f:ajax , the following inline solution will do

 <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 get them to work together?

Also, double check the need for event="click" in f:ajax so that the default event in h:selectOneRadio change , which I think you better use ...

+21
source share

All Articles