I create a dataTable component, and I want to add in header a button for hide columns, but the button doesn't fire the event.
This is the encode Method for header. I'm in the function rendering header and call this one when a header has to write the button for hide himself.
private void encodeHideColumnOption(FacesContext context,
UIComponent table, ResponseWriter writer) throws IOException {
HtmlCommandButton hide = (HtmlCommandButton) context
.getApplication()
.createComponent(HtmlCommandButton.COMPONENT_TYPE);
hide.setId("hb_" + model.getColumnIndex());
hide.setValue("X");
AjaxBehavior ajax = new AjaxBehavior();
ajax.setRender(Arrays.asList(":" + table.getParent().getClientId(context),
":messagePanel"));
ajax.setExecute(Arrays.asList(":form"));
hide.addClientBehavior(hide.getDefaultEventName(), ajax);
hide.addActionListener(new ActionListenerHideOption());
table.getChildren().add(hide);
hide.encodeAll(context);
}
This is the ActionListener Class
@SessionScoped
public class ActionListenerHideOption implements ActionListener, Serializable {
public ActionListenerHideOption(){
}
@Override
public void processAction(ActionEvent event)
throws AbortProcessingException {
System.out.println("Action Listener Fired :D");
}
}
But when I click in the button nothing happen, I verify with this question : h:commandLink / h:commandButton is not being invoked but doesnt work. Can you help me?
---- Edited ----
I'm trying different methods, but I really don't understand why I use this way and works
<h:commandButton id="hb_x" value="∅">
<f:actionListener type="package.ActionListenerHideOption" />
<f:ajax render=":form:dataTable" onevent="tableReset" />
</h:commandButton>
But the other way doesn't... Can anyOne help me?