1
votes

I need to conditionally set an attribute within JSF component tags based on a boolean's value from backing bean. How should I go for it ?

If the boolean is true then the attribute should be added/specified within the component tags or if boolean is false then that attribute shouldn't be set for that component.

2
Why do you need that ? Can you give an example ? The only thing you can do is to add on server side as @JMelnik said. I just want to know why would someone need this. Only reasonable thing for me is to set conditionally whether the column should have sort/filter. - Fallup

2 Answers

1
votes

You can either:

  • If the value is boolean - define default value you desire in bean and assign it to JSF component's attribute. e.g. rendered="#{bean.componentRendered}"
  • If there are more options for attribute (not boolean) - bind your component to backing bean and initialize it and required attributes on server-side. e.g. binding="#{bean.component}"

I am not sure if it is possible to achieve what I mentioned in second option. If it is impossible, then please edit my answer.

0
votes

although your question is not very clear to me.still i will try to answer this

1)if you have to populate a value in textfield(suppose) then u can set the value in the constructor of bean class and in constructor you can check the boolean value and accordingly set the value.

2)if you dont want to show the field then you can set rendered field to false according to the requirements.

please elaborate a bit so that we can help you more