【发布时间】:2013-11-24 20:21:24
【问题描述】:
由于 PrimeFaces 还不支持 <p:dataTable> 过滤器的转换器,我正在尝试为 <p:calendar> 实现我自己的自定义过滤器(当然,这个过滤器的设计看起来仍然有些难看。它需要应用适当的 CSS我不能)。
<p:column id="discountStartDate" sortBy="#{row.discountStartDate}" style="width:140px;">
<f:facet name="header">
Start Date<br/>
<p:calendar id="startDateFilter" converter="#{dateTimeConverter}"
timeZone="Asia/Kolkata" locale="#{localeBean.locale}"
pattern="dd-MMM-yyyy hh:mm:ss a"
readonly="#{facesContext.currentPhaseId.ordinal eq 6}"
label="Start Date"
effect="slide" required="true"
size="12"
showButtonPanel="true" navigator="true">
<p:ajax event="dateSelect" listener="#{discountManagedBean.startDateListener}"
onstart="PF('blockDataTableUIWidget').block()"
oncomplete="PF('blockDataTableUIWidget').unblock()"
update="dataTable"/>
</p:calendar>
</f:facet>
<!--No need to refer to-->
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{row.discountStartDate}" converter="#{dateTimeConverter}"/>
</f:facet>
<f:facet name="input">
<p:tooltip for="dataTableTxtDiscountStartDate" value="#{messages['tooptip.dataTable.popup.calendar']}"/>
<p:calendar id="dataTableTxtDiscountStartDate" binding="#{edStartDate}" value="#{row.discountStartDate}" converter="#{dateTimeConverter}" timeZone="Asia/Kolkata" locale="#{localeBean.locale}" pattern="dd-MMM-yyyy hh:mm:ss a" readonly="#{facesContext.currentPhaseId.ordinal eq 6}" label="#{messages['discount.startdate']}" effect="explode" required="true" showButtonPanel="true" navigator="true"/>
</f:facet>
</p:cellEditor>
</p:column>
当从日历中选择一个日期时,<p:ajax> 中指定的监听器被调用。
public void startDateListener(SelectEvent event)
{
if(event.getObject() instanceof DateTime)
{
//org.joda.time.DateTime
DateTime startDate=(DateTime) event.getObject();
System.out.println(startDate+" : "+startDate.getZone().getID()+ " : "+startDate.getZone());
}
}
在此方法中检索所选日期,但如何在 load() 方法中使用此日期? <p:dataTable> 使用 org.primefaces.model.LazyDataModel<Discount>。
有没有办法通过此侦听器方法使用此日期,以便在根据日历提供的日期过滤行后更新数据表 - <p:dataTable> - <p:calendar>?
如何在被覆盖的load() 方法中使用此日期?
@Override
public List<Discount> load(int first, int pageSize, List<SortMeta> multiSortMeta, Map<String, String> filters)
{
//Do something with filters to add the date selected from the calendar of the given filter we are talking about.
return discountService.getList(first, pageSize, multiSortMeta, filters);
}
【问题讨论】:
标签: jsf primefaces datatable jsf-2.2