can I bind a property to a submember's field?

Hi all,

I am facing this problem: I have an array of Place[]

and each Place

has a country

field which in turn, has a name

field.

I need to bind a table column to the country name of each place, so I was hoping to use #{currentRow.value['country.name']}

but I get java.lang.IllegalArgumentException: country.name

.

Can I do such a thing or do I need a workaround?

thanks a lot in advance

Mauro

[550 byte] By [maurozoom] at [2007-11-26 11:40:34]
# 1

EL allows you to use multiple dot operators. The Bracket operators are typically used to access elements of an array or (this is quite handy) a Map Object.

So to access the name property of the third element in an Object array of type Country you could use #{countrys[3].name}.

If you have some sort of DataProvider with a column called id containing values 1,2,3,4,5,6 etc the EL to retrieve the county name inside a table would look something like this: #{countrys[currentRow.value['id']].name}

The dot operator is sort of interchangeable so #{countries.currentRow.value.id.name} ought to do the same thing (Ain't tried this I must admit).

Have to wonder why you're trying to read an array like this when you have an ArrayDataprovider and ObjectDataProvider etc on the pallette?

yossarian at 2007-7-7 11:42:05 > top of Java-index,Development Tools,Java Tools...
# 2

thanks

maybe I didn't explain it very well, but of course I am using an ArrayDataProvider to access the Place[] array.

the EL:

#{currentRow.value['country.name']}

is the one I use to show a table column of country name for each place

this doesn't work, I always get the error

thanks

Mauro

maurozoom at 2007-7-7 11:42:05 > top of Java-index,Development Tools,Java Tools...
# 3

You are probably looking to use an ObjectArrayDataProvider. the base Object you get back from currentRow.value is an element of the object array.

So if i understand you correctly this should access the elements you want:

#{currentRow.value['country']}

#{currentRow.value['name']}

This asumes your Place Object looks like:

public Class Place {

String country;

String name;

....

...

}

If you really have a class that looks like this:

public Class Place{

Country country;

....

...

}

public Class Country{

String name;

String ....

....

}

then your original syntax should work.

Message was edited by:

yossarian

yossarian at 2007-7-7 11:42:05 > top of Java-index,Development Tools,Java Tools...
# 4
yes I agree my original syntax should work, but it doesn'tI had to use a workaround but I cannot get why this happensthanks anyway
maurozoom at 2007-7-7 11:42:05 > top of Java-index,Development Tools,Java Tools...
# 5

It seems an ObjectDataProvider & ObjectArrayDataProvider have optional access to public fields (default is "on"): This from the Javadoc:

-

setIncludeFields

public void setIncludeFields(boolean爄ncludeFields)

Sets the includeFields property. This affects the set of FieldKeys that this DataProvider emits. If includeFields is set to true (the default), then public fields will be included in the list of available keys (intermixed with the public properties). If it is set to false, then only the public properties will be available.

Parameters:

includeFields - true to include the public fields, or false to exclude them (and only show public properties)

You can try defining bean patterns (setters and getters) . Also try making the fields public...

yossarian at 2007-7-7 11:42:05 > top of Java-index,Development Tools,Java Tools...
# 6
This should work:#{currentRow.value['country'].name}It works fine for me.Haroon
HaroonA at 2007-7-7 11:42:05 > top of Java-index,Development Tools,Java Tools...
# 7
yes this finally worksthanks a lot Mauro
maurozoom at 2007-7-7 11:42:05 > top of Java-index,Development Tools,Java Tools...