vrijdag 24 april 2009

JSF CommandLink and CommandButton fails inside table

The problem is some commandButtons simply don't work at all. The action is never executed. I tested with a debugger and there is not even a call to the given action method :o. Overlooking spelling mistakes makes no sense because JSF would warn me for non existing methods. I found the solution in this topic: JSF and "THE TRAP!" - CommandLinks and DataTables on theserverside.com.

And I quote from http://typo.ars-subtilior.com/articles/2007/02/07/jsf-datatable-and-commandlink

The reason for this behaviour is that the DataTable modifies the id of the CommandLink during renderering, but the CommandLink does not know that it was rendererd with a different id. During the decoding of the request which was triggered by clicking the CommandLink, the ComandLinkRenderer looks at a hidden form parameter. If the value of that form parameter equals the id of the CommandLink, an action is queued. If not, nothing is done.

Since the DataTable changes the ids, the value of the hidden form parameter does not match the id of the CommandLink.


Some solutions:

- change request scope of bean to session scope in faces-config.xml (only workaround)
- adding preserveDataModel="true" to dataTable tag (didn't help for me!)
- using tomhawaks saveState tag (didn't try this)
- override commandLinkRenderer

Also check this thread: http://forums.sun.com/thread.jspa?threadID=5116147

Geen opmerkingen:

Een reactie posten