How and when should I load the model from database for JSF dataTable

Do it in bean’s @PostConstruct method. @ManagedBean @RequestScoped public class Bean { private List<Item> items; @EJB private ItemService itemService; @PostConstruct public void init() { items = itemService.list(); } public List<Item> getItems() { return items; } } And let the value reference the property (not method!). <h:dataTable value=”#{bean.items}” var=”item”> In the @PostConstruct you have the advantage … Read more

Why is the getter called so many times by the rendered attribute?

EL (Expression Language, those #{} things) won’t cache the result of the calls or so. It just accesses the data straight in the bean. This does normally not harm if the getter just returns the data. The setter call is done by @ManagedProperty. It basically does the following: selector.setProfilePage(request.getParameter(“profilePage”)); The getter calls are all done … Read more

C# add validation on a setter method

If you want to validate when the property is set, you need to use non-auto properties (i.e., manually defined get and set methods). But another way to validate is to have the validation logic separate from the domain object. class Customer { public string FirstName { get; set; } public string LastName { get; set; … Read more

Python overriding getter without setter

Use just the .getter decorator of the original property: class superhuman(human): @human.name.getter def name(self): return ‘super ‘ + self._name Note that you have to use the full name to reach the original property descriptor on the parent class. Demonstration: >>> class superhuman(human): … @human.name.getter … def name(self): … return ‘super ‘ + self._name … >>> … Read more

Allen Holub wrote “You should never use get/set functions”, is he correct? [duplicate]

I don’t have a problem with Holub telling you that you should generally avoid altering the state of an object but instead resort to integrated methods (execution of behaviors) to achieve this end. As Corletk points out, there is wisdom in thinking long and hard about the highest level of abstraction and not just programming … Read more

In Objective-C on iOS, what is the (style) difference between “self.foo” and “foo” when using synthesized getters?

I have personally settled on using an underscore prefix for ivars, and this kind of synthesize @synthesize name = _name; That way I don’t mix them up. The major issue with not using self is that this code _name = … is very different from self.name = … When the @property uses the retain option. … Read more