aspose file tools
The moose likes JSF and the fly likes JSF Render Attribute - Array Length Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF Render Attribute - Array Length" Watch "JSF Render Attribute - Array Length" New topic

JSF Render Attribute - Array Length

Cory Cowgill

Joined: Mar 15, 2011
Posts: 4
Simple question which I can't find an answer to by searching the forums.

How do I use JSF EL Binding to get the length of an Array in a backing bean?


If the size of an Array is 0, I want to set the render attribute of a <h:dataTable> to false.

With a managed backing bean like this:

public class acctBean

public Account[] accts;

public Account[] getAccts() {
return accts;

I'd like to render/not render the datatable like this:

<h:dataTable class="acctTable" border="1" value="#{acctBean.accts}" var="item" rendered="#{acctBean.accts.length > 0}">

However, this throws an exception:

SEVERE: java.lang.NumberFormatException: For input string: "length"
at java.lang.NumberFormatException.forInputString(

Suggestions? Google isn't giving me a search result for an answer yet....

Stefan Evans

Joined: Jul 06, 2005
Posts: 1517
This link has some related answers in it

If you can use facelets, then you might be able to employ the #{fn:length(acctBean.accts)}

If you have a JEE6 container, and convert the array to a Collection, you should be able to invoke: #{acctBean.accts.size()> 0}

Otherwise the other solution is to add a workaround method to your backing bean which the EL can invoke.

and access it as #{acctBean.lengthOfArray}
Cory Cowgill

Joined: Mar 15, 2011
Posts: 4
Thanks Stefan!

I appreciate the feedback and the mutliple solutions.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16879

OR, you could just use simple EL.

The "empty" operator is fairly flexible. Depending on context, it can check for null objects, empty strings, or empty arrays.

Customer surveys are for companies who didn't pay proper attention to begin with.
I agree. Here's the link:
subject: JSF Render Attribute - Array Length
It's not a secret anymore!