I have an IceFaces form with several HtmlCommandButtons on it. I have some input fields that have attached validators. The validation works well, but runs and blocks the process even if I press buttons different than the submit one. Logical because all my buttons are basically the same. The question is: how to distinguish between the buttons from the aspect of validation?
I cannot provide XHTML snippet because my form is build dynamically from Java code. The buttons are created this way:
HtmlCommandButton comp = new HtmlCommandButton();
comp.setId("btn" + StringUtil.toId(label) + "_" + action);
comp.setTitle(label);
comp.setValue(label);
comp.setStyleClass("commandexbutton commandexbutton-" + StringUtil.toId(label));
comp.addActionListener(JSFBuilderHelper.createActionListener(getActionListenerStr()));
comp.setPartialSubmit(true);
At simplest, you could set the
UICommandcomponent’simmediateattribute totrue. It will then skip the processing ofUIInputcomponents which does not have this attribute totrue.For a detailed explanation of the usage of this attribute, see the 2nd half of this answer.
If that’s not an option, then your best bet is to put the cancel button in a separate form so that it effectively ends up like:
If that’s also not an option due to design/layout restrictions (read: not fixable by just CSS/JS), then you basically need to check in every validator which button is been pressed. You could check that by the presence of the button’s client name (ID) in the request parameter map. For example, as component’s attribute:
or
or in the beginning of the validator’s
validate()method:or