Rajat Gupta
Rajat Gupta

Reputation: 26587

Conditionally set an attribute within JSF component tag

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.

Upvotes: 1

Views: 893

Answers (2)

d1e
d1e

Reputation: 6442

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.

Upvotes: 1

Anil Sharma
Anil Sharma

Reputation: 558

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

Upvotes: 0

Related Questions