-1

In my table, I just want to get an attribute, why do I have to write a getter in my data object?

I'm declaring a variable 'o' (that's my data object) and want to get the public value 'commission'. It doesn't work without a getter method.

view.xhtml:

<h:dataTable value="#{ABList.unreadedABs}" var="o"
                styleClass="ABList-table"
                headerClass="ABList-table-header"
                rowClasses="ABList-table-odd-row,ABList-table-even-row">

   <h:column>
    <f:facet name="header">Commission</f:facet>
    #{o.commission}
    </h:column>

dataobject:

public class AB {
    public String commission;
}
Tiny
  • 27,221
  • 105
  • 339
  • 599
jcomouth
  • 324
  • 3
  • 16
  • 1
    `o.commission` refers to the getter method of the `commission` property - (`getCommission()`) in the associated backing bean and not the `commission` property itself. – Tiny Jul 25 '14 at 11:00
  • Thanks for your reply, that make sense. But I haven't expected this behavior, in Java object.attribute tries to get me an attribute, not to call a method. I guess there is no possibility to call the attribute, isn't it? – jcomouth Jul 25 '14 at 11:36
  • Attributes require corresponding public getter methods to access their values and public setter methods to set their values, if needed. – Tiny Jul 25 '14 at 11:40

1 Answers1

0

That o.commission refers to the getter of the property is due to the default EL resolver, which is just implemented that way. You could write your own EL resolver which resolves public properties directly.

Have a look at the question and answer from With Java EL 2.2 / JSF2 Is it possible to do field access rather than getters/setters? .

Community
  • 1
  • 1
user1983983
  • 4,793
  • 2
  • 15
  • 24