Promotion Methods vs. Named Classes

I wonder which way is preferable: to access bean vars by the full class .property or directly access only the property name according to the manufacturerโ€™s method? Especially if the project becomes much larger with many classes, services, facades, etc.

@Named public Service { List<Customer> getCustomers(); } use: <h:dataTable value="#{service.customers}" /> 

or

 public Service { @Produces @Named List<Customer> getCustomers(); } use: <h:dataTable value="#{customers}" /> 

The first advantage for me is that if I need to change jsf, I always know exactly which class I need to change due to the fully qualified name.

This will be a drawback for the second method, but, on the contrary, it is better to read in the case of many services and classes.

What would you say to the experts?

+6
source share
2 answers

IMO, I go with the first route. It is also easier with refactoring (assuming your IDE is also renamed to JSF pages). Although, to be honest, I would expect that to be a personal taste.

Another advantage of using service.property is the ability to modify the property and reflect it in the user interface. If you use a manufacturer, this producer is called only once for each area, where when calling getter all the time (another performance compromise). There are many ways to do something, and everything that works is fine, use this method.

0
source

I would go with the first option, as I always liked to link to the Managed Bean related to this page. I believe this is more understandable code.

0
source

Source: https://habr.com/ru/post/909656/


All Articles