Sometimes, one needs to programmatically access a JSF component that is used on a page. For such cases, all JSF components have a binding
attribute that can be used to bind the component to a property in a backing bean. An example can be found on our Kids.xhtml
page, where the delete button is bound to the kidsTable
bean in order to make it possible to dynamically enable and disable the button, depending on the selection in the table:
<tr:commandButton actionListener="#{kidsTable.deleteSelected}"
text="#{msg.delete}"
disabled="#{!kidsTable.deleteEnabled}"
partialSubmit="true"
id="btnDelete"
binding="#{kidsTable.deleteButton}" />
The kidsTable
bean has a deleteButton
property:
public class KidsTable { ... private CoreCommandButton deleteButton; public CoreCommandButton getDeleteButton() { return deleteButton; } public void setDeleteButton( CoreCommandButton deleteButton) { this.deleteButton = deleteButton; } ... }
This is all fine, and it works as intended. However...