问题
I have a JSF component which is initialized from a managed bean's getter getProperty()
. Is it mandatory to also have a setter setProperty()
in that managed bean?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/7580167/are-both-getters-and-setters-mandatory-in-jsfs-managed-beans