File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes h:commandlink and a4j:commandlink only working on second click when in a datatable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "h:commandlink and a4j:commandlink only working on second click when in a datatable" Watch "h:commandlink and a4j:commandlink only working on second click when in a datatable" New topic
Author

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

Tasneem Bhyat
Greenhorn

Joined: Dec 17, 2008
Posts: 4
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

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Dec 17, 2008
Posts: 4
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>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: h:commandlink and a4j:commandlink only working on second click when in a datatable
 
Similar Threads
Selected row highlighted only for split second
Unable to submit form in single click
command link inside the <hx:commandExRowAction>
Command button useless
Showing a List of Maps in a dataTable