You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by hilz <hs...@hotmail.com> on 2005/12/08 18:24:19 UTC
dataTable question
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
Re: dataTable question
Posted by Aleksei Valikov <va...@disy.net>.
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.
You don't need setter for read-only operations.
Bye.
/lexi
Re: dataTable question
Posted by Simon Kitching <sk...@obsidium.com>.
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
Posted by gr...@intellicare.com.
news <ne...@sea.gmane.org> wrote on 12/08/2005 05:02:15 PM:
> hilz wrote:
> 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.
I believe it is enough to have just a getter (if that's all you want to do
in your app).
>
> and to put the question in another form, is what i did a normal thing to
> do? or did it work just by coincidence?
So, no I don't think it worked just by coincidence..:)
>
> thanks
Regards,
Geeta
Re: dataTable question
Posted by hilz <hs...@hotmail.com>.
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?
thanks