简体   繁体   中英

Producer Methods vs Named Classes

I wonder which way is to be preferred: to access backing bean vars by full classname.property, or to direct access only the property name by producer method? Especially if the project grows much bigger with lot of 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}" />

First way advantage to me is, that if I have to change the jsf, I always know exactly which class I have to modify due to the full qualified name.

This would obv be the disadvantage for the 2nd way, but which in contrast is way better to read in case of many services and classes.

What would you experts say?

I would go with the first option since I like to always reference the Managed Bean that's relevant to the page. I believe it's a more understandable code.

IMO, I go with the first route. It's also easier with refactoring (assuming your IDE will rename in JSF pages as well). Although, honestly this I would expect to be a personal flavor thing.

Another advantage of using the service.property is the ability to modify the property and have that be reflected on the UI. If you're using a producer, that producer is only called once per scope where as the getter is called all the time (another performance trade off). There are lots of ways to go about doing things and and whatever works for is great, use that way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM