简体   繁体   English

如何访问Java bean的非getter / setter方法

[英]how to access a non getter/setter method of a java bean

I have an xhtml page that gets values from a java bean: 我有一个从Java bean获取值的xhtml页面:

<h:dataTable value="${myBean.getAccounts}" var="account">
        <h:column>
            <f:facet name="header">Account ID</f:facet>
            #{account.id}
        </h:column>
        <h:column>
            <f:facet name="header">Account Name</f:facet>
            #{account.name}
        </h:column>

</h:dataTable>

The problem is that when I run this on a Tomcat 7 server, I get an error: getAccounts is not a myBean property. 问题是,当我在Tomcat 7服务器上运行此命令时,出现错误:getAccounts不是myBean属性。 The java class's getAccounts method is a standalone method that returns some results. Java类的getAccounts方法是一个独立的方法,它返回一些结果。

Is there no way I can call this method? 我无法调用此方法吗?

Any help is appreciated. 任何帮助表示赞赏。

Thanks! 谢谢!

The property name is accounts , not getAccounts . 该属性名称是accounts而不是getAccounts getAccounts is a getter that returns the property accounts getAccounts是返回属性帐户的getter

EL将带有get / set前缀的任何方法都视为属性,因此,如果使用任何方法调用该方法,则可以省略get / set部分。

Jeff's answer is correct. 杰夫的答案是正确的。 Just some additional info: 只是一些其他信息:

Your method is called getAccounts() but in EL you need to say #{mybean.accounts} 您的方法称为getAccounts(),但在EL中,您需要说#{mybean.accounts}

There is a good complete example of using ah:dataTable here 有使用啊一个很好的完整的例子:dataTable的位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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