I'm trying to update the styleClass of a JSF component if a certain condition is met by the set value. I can make it work by rerending the whole component which is triggered by some ajax event. However, the provided events only fire at inopportune times, i.e. when the user is still interacting with the component causing an interuption due to the redraw.
Is the a way to update the styleClass without the redraw?
Working code snippets, but with the undesired behavior:
<p:selectCheckboxMenu id="input" value="#{bean.value}">
<f:selectItems value="#{bean.options}" />
<f:attribute name="styleClass" value="#{bean.highlight(bean.value)}" />
<p:ajax event="toggleSelect" update="input" />
<p:ajax event="change" update="input" />
</p:selectCheckboxMenu>
And the backing bean:
@ManagedBean
@ViewScoped
public class Bean {
private List<String> value;
private Map<String, String> options;
public String highlight(Object value) {
return value == null || value instanceof Collection<?> && ((Collection<?>) value).isEmpty() ? "" : "ui-state-active";
}
/* getters & setters */
}