Are both getters and setters mandatory in JSF's managed beans?

a 夏天 提交于 2019-12-10 17:26:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!