【发布时间】:2015-06-03 23:40:42
【问题描述】:
我正在尝试从日历 dateSelect 事件更新 dateTable。 我是使用 PrimeFaces 和 Tomcat 的新手。
这是我的代码
index.xhtml
<h:body>
...
<h:form id="cites">
<p:calendar id="calendari" value="#{indexBean.calendari}" mode="inline" locale="va">
<p:ajax event="dateSelect" listener="#{indexBean.onDateSelect}" update="taulaHores"/>
</p:calendar>
<p:dataTable id="taulaHores" var="hores" value="#{indexBean.hores}"
widgetVar="taulaHores" emptyMessage="Sense resultats"
filteredValue="#{indexBean.horesFiltrades}" style="width:1000px"
selection="#{indexBean.horaSeleccionada}" rowKey="#{hores.hora}">
<p:column selectionMode="single" style="width:16px;text-align:center"/>
<p:column id="horaCol" headerText="Hora">
<h:outputText value="#{hores.hora}">
<f:convertDateTime type="time" pattern="HH:mm"/>
</h:outputText>
</p:column>
<p:column id="numeroHistoriaColBis" headerText="NHC" >
<h:outputText value="#{hores.nhc}" rendered="#{not null}" />
<h:outputText value="Lliure" rendered="#{hores.nhc eq null}" />
</p:column>
<p:column id="nomColBis" headerText="Nom" >
<h:outputText value="#{hores.nom}" rendered="#{not null}" />
<h:outputText value="" rendered="#{hores.nom eq null}" />
</p:column>
<p:column id="lliangesColBis" headerText="Llinages" >
<h:outputText value="#{hores.llinages}" rendered="#{not null}" />
<h:outputText value="" rendered="#{hores.llinages eq null}" />
</p:column>
</p:dataTable>
</h:form>
</h:body>
IndexBean.java
public IndexBean() {
omplirHores(new Date(System.currentTimeMillis()));
}
public void onDateSelect(SelectEvent event) {
omplirHores((Date)event.getObject());
}
private void omplirHores(Date dia){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
this.hores = GenericDAO.sql("SELECT Hores.hora as hora, Hores.numeroHistoria as nhc, Persona.nom as nom, Persona.llinages as llinages " +
"FROM Hores LEFT JOIN Persona ON Hores.numeroHistoria=Persona.numeroHistoria " +
"WHERE hora>='"+dateFormat.format(dia)+" 00:00:00' AND hora<='"+dateFormat.format(dia)+" 23:59:59'" +
"ORDER BY Hores.hora ASC;");
System.out.println("llistahores " + this.hores.size());
}
然后,当 index.xhtml 被加载时,dataTable 'taulaHores' 被正确填充。问题是当我在日历中选择一个日期时,dataTable 上的行会消失,并且不会使用来自 sql 查询的新值进行更新。
更多信息,我在日志中看到'hores'的大小是正确的。
请问有什么想法吗?
提前致谢
【问题讨论】:
-
我注意到如果在日期选择后按F5,表格的内容会更新
-
已解决!!! 只需删除
filteredValue="#{indexBean.horesFiltrades}"属性 -
你不需要大喊“解决了!!!”在标题中并在编辑摘要或问题评论中发布答案。我回滚了标题编辑。只需在下面发布答案作为答案。这样,问题将出现在列表中并作为“已回答”进行搜索。当您将答案标记为已接受时,该问题也将出现在列表中并搜索为“已解决”。这是一个问答网站,而不是老式的讨论论坛。
标签: jsf primefaces datatable calendar