changing styleClass on Condition for primefaces components

primefaces

Solution

You can do this, but it needs little modification. You should return string which represents class name:

styleClass="#{(bean.comment==null) ? 'style1' : 'style2'}"

Another approach is to calculate this condition in backing bean, and use simpler EL:

styleClass="#{bean.style}"

and in backing bean:

public String getStyle() {
  return (comment == null) ? "style1" : "style2";
}

Problem

Is there any way to change styleClass based on condition for primefaces components? if there is, please suggest me. I wrote like this.. ``` styleClass="#{(bean.comment==null) ? style1 : style2}" ``` is it correct way to give value for styleClass? please suggest me better ways if any. thank u

Original source