[英]Can't access managed bean method using JSF
嗨,我正在尝试访问和调用JSF页面中托管bean内的方法。 这是JSF页面的相关部分:
<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>
这是托管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;
}
}
我收到一条错误消息:... .TweetManager'没有属性'getTweets'。
getTweet()
不是属性 ,它是属性的访问器 (或“ getter”)。
该属性的名称为tweets
(不包含get
,首字母小写)。 所以:
<c:forEach items="#{tweetManager.tweets}" var="item">
请记住, boolean
属性具有像“ is”(vg isRich()
)这样的“ getter”
并记住我对使用泛型的评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.