Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing styleClass on Condition for primefaces components

Tags:

primefaces

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

like image 713
swaps Avatar asked Dec 30 '25 13:12

swaps


1 Answers

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";
}
like image 153
partlov Avatar answered Jan 06 '26 07:01

partlov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!