简体   繁体   English

如何在JSF中使用dataTable访问对象方法?

[英]How to access object methods using dataTable in JSF?

I'm working with LastFM api, let's say I have a class called Artist which I call in this dataTable : 我正在使用LastFM api,假设我有一个名为Artist的类,我在此dataTable调用:

<h:dataTable var="artist" value="#{personEAO.topArtists}" >
    <h:column>Artist : #{artist.name} </h:column>
</h:dataTable>

Artit have a field which refers to his picture : 阿蒂特(Artit)有一个领域参考他的照片:

artist.getImageURL(ImageSize.LARGE)

Which works fine, but how do I call this method in my jsf page using dataTable ? 哪个工作正常,但是如何使用dataTable在我的jsf页面中调用此方法?

I searched around for Javadocs, but I couldn't find them anywhere. 我到处搜索Javadocs,但是在任何地方都找不到它们。 The answer depends on what kind of constant ImageSize.LARGE is. 答案取决于哪种恒定的ImageSize.LARGE

If ImageSize is an enum, just do: 如果ImageSize是一个枚举,请执行以下操作:

<h:graphicImage value="#{artist.getImageURL('LARGE')}" />

But if it isn't and is thus a public static constant, then one of the ways is to wrap it in some helper bean which returns exactly that: 但是,如果不是,因此它是一个public static常量,那么一种方法是将其包装在一些辅助bean中,该bean确切地返回:

<h:graphicImage value="#{artist.getImageURL(someHelperBean.ImageSize_LARGE)}" />

I of course assume that your environment supports EL 2.2. 我当然假设您的环境支持EL 2.2。

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

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