Are both getters and setters mandatory in JSF's managed beans?
I have a JSF component which i开发者_如何学JAVAs initialized from a managed bean's getter getProperty()
. Is it mandatory to also have a setter setProperty()
in that managed bean?
It depends.
Some property bindings must be read-write. For example, if you bind the value of a component that implements EditableValueHolder
. Other properties can be read-only.
If you use the binding
attribute for dynamically creating component instances, this must also be read-write as per the contract defined in the specification.
No, not mandatory. Unless you want to be able to bind the property in a way that allows its value to be changed.
EG. If you have a list of objects you want to display in a data table then a setter may not be needed. If you bind a string property to an textInput then you will need a setter.
精彩评论