Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

h:commandlink and a4j:commandlink only working on second click when in a datatable

 
Tasneem Bhyat
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am having a problem with both a4j and h comandlink and commandbutton. I have a datatable and the link inside a column. However, the action does not get called on the first click. It always only gets called when user clicks for the second time.

Can someone please help....

Thanking you
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to make sure that the datamodel is the same during the apply request values phase of the subsequent request as it was during the render response phase of the initial requst. To the point, the getter of the datamodel must return the same value in the subsequent request. The usual way is to set the datamodel in the constructor of the bean.

For more about using datatables you may find this article useful: http://balusc.blogspot.com/2006/06/using-datatables.html
 
Tasneem Bhyat
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Thank-you very much for your reply. I just wanted to confirm something with you please. I assume that by datamodel, you mean the list that is going to be populated in the datatable. My scenario is as follows :
User clicks on a View menu item. He/she then has a search criteria, and then clicks the search button. In my bean, I populate the data tables list, in a method called doSearch() <this populates the adminUserList>. It then reloads the same page, and because I have a rendered attribute on the datatable to check if the list is populated, it then populates it.

PS. My code is as follows

public Collection<AdminUserEntity> doSearch() {
logger.info("doSearch");
foundResults = false;
//check which of the three search criteria was entered
if((getSearchName() == null | getSearchName().trim().equals("")) && (getSearchSurname() == null | getSearchSurname().trim().equals(""))
&& (getSearchUserName() == null | getSearchUserName().trim().equals(""))) {
if(userSession.getAdminUser().getAccessLevel().getDescription().trim().equals("SuperUser")) {
adminUserList = adminUserManager.getAllAdminUsers();
} else {
adminUserList = adminUserManager.getAllAdminUsersForDomain(userSession.getAdminUser().getDomain().getDomainId());
}
}


and the xhtml page is
<rich:dataTable id="dtAdminUser"
value="#{userAdmin.adminUserList}"
var="adminUser"
onRowMouseOver="this.style.backgroundColor='#F8F8F8'"
onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
width="100%" rendered="#{userAdmin.adminUserList.size() > 0
}" rowkey="#{adminUser.adminUserId}">
<rich:column width="30px">
<f:facet name="header"></f:facet>
<a4j:commandButton image="/img/pencil.png" rendered="#{userAdmin.showUpdateBtn}" immediate="true" action="#{userAdmin.administerUser(adminUser.adminUserId)}"/>
<a4j:commandButton image="/img/pencil_delete.png" rendered="#{userAdmin.showDeleteBtn}" immediate="true" action="#{userAdmin.administerUser(adminUser.adminUserId)}"/>
<a4j:commandButton image="/img/magnifier.png" rendered="#{userAdmin.showViewBtn}" immediate="true" action="#{userAdmin.administerUser(adminUser.adminUserId)}"/>
</rich:column>
<rich:column>
<f:facet name="header">Name</f:facet>
<hutputText value="#{adminUser.name}" />
</rich:column>
<rich:column>
<f:facet name="header">Surname</f:facet>
<hutputText value="#{adminUser.surname}" />
</rich:column>
<rich:column>
<f:facet name="header">adminUserName</f:facet>
<hutputText value="#{adminUser.userName}" />
</rich:column>


</rich:dataTable>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic