Reputation: 127
Hi I'm trying to access and call a method inside a managed bean in my JSF page. Here is the relevant part of the JSF page:
<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://xmlns.jcp.org/jsf/passthrough"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns="http://www.w3.org/1999/xhtml"
template="./template.xhtml">
<ui:define name="right">
<c:forEach items="#{tweetManager.getTweets}" var="item">
<h:link value="#{item.username}" />
Likes: <h:outputText value="#{item.likes}" />
<h:link id="" value="like" /> <br />
<textarea>
<h:outputText value="#{item.text}" />
</textarea>
</c:forEach>
</ui:define>
Here is the managed bean.
@ManagedBean
@RequestScoped
public class TweetManager {
private Tweet TweetEntity;
private List<Tweet> Tweets;
@EJB
private TweetService TweetService;
@PostConstruct
public void init(){
TweetEntity = new Tweet();
}
public void setTweet(Tweet tweetEntity){
this.TweetEntity = tweetEntity;
}
public Tweet getTweet(){
return this.TweetEntity;
}
public void Save(){
TweetService.create(TweetEntity);
}
public List<Tweet> getTweets(){
Query query = TweetService.getEntityManager().createNativeQuery("SELECT * FROM tweet");
Tweets = query.getResultList();
return Tweets;
}
}
I'm getting an error saying: ... .TweetManager' does not have the property 'getTweets'.
Upvotes: 2
Views: 1638
Reputation: 24780
getTweet()
is not a property, it is the accessor (or "getter") of the property.
The name of the property is tweets
(without the get
, first letter to lowercase). So:
<c:forEach items="#{tweetManager.tweets}" var="item">
Remember that boolean
properties have "getters" like "is" (v.g. isRich()
)
And keep in mind my comment about using generics.
Upvotes: 3