您好我正在编写一个项目,以允许Lesson表中的所有特定课程在页面上单独显示。所以所有的高尔夫课程都在高尔夫页面,所有的网球都在另一个,等等。下面是我用过的豆子
//collects the lessons for specific sport number
public Collection<Lesson> getLessonForSpecificSport(){
Map<String, String> parameter=FacesContext.getCurrentInstance().
getExternalContext().getRequestParameterMap();
//parse the sport=x from the url to an integer
int sportNumber = Integer.parseInt(parameter.get("sport"));
//if sport number is equal to zero, display all lessons
if (sportNumber==0)
{
return (Collection<Lesson>) this.getLessonList();
}
//else display the lessons corresponding to the value within sportNumber
else
{
//return the sport.getLessonCollection() result
return em.find(Sport.class, sportNumber).getLessonCollection();
}
}
我想知道的是我如何能够使用dataTable在页面上呈现这一点,最新的尝试就是这样,但是当我运行Netbeans时页面上没有任何内容
<h:dataTable value="#{getLessonForSpecificSport.lesson}" var="item">
<h:column>
<f:facet name="header">
Class no
</f:facet>
<f:param name="sportno" value="#{lesson.sportno}" />
</h:column>
</h:dataTable>
答案 0 :(得分:0)
你可能想做这样的事情:
<h:dataTable value="#{listBean.lessonForSpecificSport}" var="lesson">
<h:column>
<f:facet name="header">
Class no
</f:facet>
<h:outputText value="#{lesson.sportno}" />
</h:column>
</h:dataTable>
或
<h:dataTable value="#{listBean.lessonForSpecificSport}" var="lesson">
<h:column>
<f:facet name="header">
Class no
</f:facet>
#{lesson.sportno}"
</h:column>
</h:dataTable>
假设类Lesson
中有一个名为getSportno()
的方法,并且支持bean名称为listBean
。
请注意,如果调用Lesson
方法getSportNo()
,则应在dataTable中使用#{lesson.sportNo}
。即方法名称区分大小写,只有 get 前缀后面的第一个字母以小写形式使用。