The class does not have property [duplicate]
Asked Answered
W

1

9

In my entity:

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(unique=true, nullable=false)
private int tId;
....
public int getTId() {
      return this.tId;
}

public void setTId(int tId) {
      this.tId = tId;
}

And code in my JSF page:

<ui:repeat value="#{techCat.techsOfCat}" var="post">
    <h:outputText value="#{post.getTId()}"/>
        ...
</ui:repeat>

The result is good. But if i code:

<ui:repeat value="#{techCat.techsOfCat}" var="post">
    <h:outputText value="#{post.tId}"/>
    ...
</ui:repeat>

I faced an error:

value="#{post.tId}": The class 'model.Technology' does not have the property 'tId'.

I really don't understand that error. Can you explain to me? Thanks

Wally answered 5/8, 2013 at 15:30 Comment(0)
C
17

The error means that correct getters and setters could not be located for your property. The correct syntax for your getter and setter should be:

public int gettId() {
    return tId;
}

public void settId(int tId) {
    this.tId = tId;
}

If you are not sure- always use code generation for your getters and setters.

If you are interested in the specific convention, your getter and setter will relate to TId not tId.

Charo answered 5/8, 2013 at 15:36 Comment(4)
-1 for saying that getter/setter are wrong (instead, it's the property name in EL which is wrong), +1 for pointing out a link with actually the right answer / technical explanation.Powe
He defines his property as 'private int tId' so I thought if he wants something that corresponds to this, he should use getters and setters as defined in my answer? You can also change the property name in EL of course. Or am I missing something?Charo
EL properties do not correspond to private bean properties. They correspond to public bean getter/setter. The in your answer proposed getter/setter syntax is invalid according Javabeans specification (I haven't tested it, but I wouldn't be surprised if it still causes PropertyNotFoundException on certain EL impls/versions and/or bean introspection APIs). OP's original getter/setter syntax was valid, it's just the EL property name which is wrong based on the getter/setter syntax.Powe
Thank you, so the point is simply that when thinking about EL properties, one should not be trying to make a link between them and variables in the class. I guess it depends what he is trying to achieve (variable name and EL name being the same seemed to me like his goal).Charo

© 2022 - 2024 — McMap. All rights reserved.