开发者

How to access to getFirst() & getLast() from a JSF page?

I have a java object defined as List< List< LinkedList > > >. However, when I print the data on a table and do the next thing, it works:

<f:verbatim>selectableDiv.first=</f:verbatim><h:outputText value="#{column[rowCount][0]"/>

However, if do any of the following things, it crashes:

<f:verbatim>selectableDiv.first=</f:verbatim><h:outputText value="#{column[rowCount].first}"/>
<f:verbatim>selectableDiv.first=</f:verbatim><h:outputText value="#{column[rowCount].getFirst()}"/>
<f:verbatim>selectableDiv.first=</f:verbatim><h:outputText value="#{column[rowCount].getFirst}"/>
<f:verbatim>selectableDiv.first=</f:verbatim><h:outputText value="#{column[rowCount].First}"/>
<f:verbatim>selectableDiv.first=</f:verbatim><h:outputText value="#{column[rowCount]['first']}"/>

I would like to access th开发者_JAVA技巧e LinkedList methods getFirst() and getLast(). How could I do this?

Thanks a lot for your support! ;-)


That's not possible in standard EL. Whenever the object is an instance of List, it get special treatment by ListELResolver. You can only access the item by an integer index. EL has no specialized support for LinkedList. You'd need to write a custom ELResolver for this, but easier is to just wrap the LinkedList in a Javabean and delegate the calls to it.


i suggest you to write a method to your controller (home) class for getting inner lists by index.


As an alternative to what BalusC says (which is good advice), you can also create your own EL function.

This is actually rather simple and provides more reuse if you need this kind of functionality on more pages.

With a custom EL function you can eg say:

#{funct:first(column[rowcount])}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜