本文介绍了@Produces比EL表达式中的getter效率更高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想知道这两个代码片段中哪个更有效.

I'm wondering which of those two code snippets is more efficient.

第一个

userSearch.xhtml中:

<rich:dataTable
    var="user"
    value="#{userSearchResultList}"
    rendered="#{not empty userSearchResultList}">
...
</rich:dataTable>

UserSearchAction.java中:

@Produces @RequestScoped
@Named("userSearchResultList")
public List<User> getResultList() {
    return resultList;
}


第二个

userSearch.xhtml中:

<rich:dataTable
    var="user"
    value="#{userSearchAction.resultList}"
    rendered="#{not empty userSearchAction.resultList}">
...
</rich:dataTable>

UserSearchAction.java中:

public List<User> getResultList() {
    return resultList;
}


在两种解决方案中,我的resultList变量都由方法UserSearchAction.search()填充.


In both solutions, my resultList variable is filled by a method UserSearchAction.search().

我正在使用JBoss 7.0.2.Final和RichFaces 4.1.0.Final.

I'm using JBoss 7.0.2.Final and RichFaces 4.1.0.Final.

更笼统地说,我想知道写生产者是否比调用JSF文件中某些类的子属性更好.

More generally, I wanted to know if it's better to write producers than to call sub-properties of some classes in JSF files.

推荐答案

这取决于您的生产者如何限定所生产的产品.如果它是依赖范围的(意味着您没有它的范围,也没有包含类的范围),它最终将是相同的,可能更少,这取决于您在该方法中必须执行的操作.

That depends on how your producer scopes what is being produced. If it's dependent scoped (meaning you don't have a scope on it, nor on the containing class) it ends up being the same, possibly less depending what it is you are having to do inside that method.

在您的示例中,它应该更加高效,因为该生产者方法仅应(按请求)被调用一次.

In your example it should be more efficient because that producer method should only be called once (per request).

这篇关于@Produces比EL表达式中的getter效率更高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:37