hilz wrote:
hilz wrote:
Hi
I have a dataTable where the data is a list of objects...
now if in my table, i have something like this:
<h:dataTable .... var="currentRow">
<h:column ...>
<h:outputText ... value="#{currentRow.unitPrice}"/>
the objects in the list associated with the table have a method
public Double getUnitPrice(){
...
}
but there is no unitPrice property, and no setUnitPrice(...) method.
The getUnitPrice method calculates the unit price from some other
properties.
It is working fine with no problem so far... but I like to know if
this is ok or if this could cause any unforseen problems in some other
situation or in an app server different than what i am currently using.
thanks
In other words... does the property that i bind to the outputText have
to be a real bean property with a getter and a setter? or could it be
just a getter (like what i showed in the example above) without the
actual property and the setter.
and to put the question in another form, is what i did a normal thing to
do? or did it work just by coincidence?
I think your code is fine. Java bean "properties" are virtual things;
there doesn't have to be a corresponding member on the class.
And properties are allowed to be "read-only" (ie just a getter),
"write-only" (just a setter) or "read-write" (both getter and setter
defined).
See the javadoc for class java.beans.Introspector for more details on
what defines a "property" of a class. You could even try passing your
class to the Introspector.getBeanInfo method, and printing out the
PropertyDescriptor objects returned; that's the final test of what a
"property" is.
Regards,
Simon
- Re: dataTable question Simon Kitching
-