我正在尝试使用this在Primefaces数据表中实现selectOneMenu作为过滤器。当我尝试过滤数据表时,它显示每次都没有找到记录。如果我错过了什么,请告诉我。
<p:column filterBy="#{book.timeSlotId}" filterMatchMode="exact">
<f:facet name="header">
<h:outputText value="#{bundle.ListBookingDetailsTitle_timeSlotId}"/>
</f:facet>
<f:facet name="filter" >
<p:selectOneMenu onchange="PF('bookDetTable').filter()" >
<f:selectItem itemLabel="Select One" itemValue="#{null}"
noSelectionOption="true" />
<f:selectItems value="#{bookingTimeSlotsController.itemsAvailableSelectOne}"
var="timeSlotIdItem"
itemValue="#{timeSlotIdItem}" itemLabel="#{timeSlotIdItem.toString()}" />
</p:selectOneMenu>
</f:facet>
<h:outputText value="#{book.timeSlotId.toString()}"/>
</p:column>
任何帮助都很适合。
实体类确实有hashCode()和equals方法
@Override
public int hashCode() {
int hash = 0;
hash += (timeSlotId != null ? timeSlotId.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof BookingTimeSlots)) {
return false;
}
BookingTimeSlots other = (BookingTimeSlots) object;
if ((this.timeSlotId == null && other.timeSlotId != null) || (this.timeSlotId != null && !this.timeSlotId.equals(other.timeSlotId))) {
return false;
}
return true;
}
@Override
public String toString() {
return JsfUtil.convertTimetoString(timeSlotStime) + " - " + JsfUtil.convertTimetoString(timeSlotEtime);
}
转换器
@FacesConverter(forClass = BookingTimeSlots.class)
public static class BookingTimeSlotsControllerConverter implements Converter {
@Override
public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
if (value == null || value.length() == 0) {
return null;
}
BookingTimeSlotsController controller = (BookingTimeSlotsController) facesContext.getApplication().getELResolver().
getValue(facesContext.getELContext(), null, "bookingTimeSlotsController");
return controller.getFacade().find(getKey(value));
}
java.lang.Integer getKey(String value) {
java.lang.Integer key;
key = Integer.valueOf(value);
return key;
}
String getStringKey(java.lang.Integer value) {
StringBuilder sb = new StringBuilder();
sb.append(value);
return sb.toString();
}
@Override
public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
if (object == null) {
return null;
}
if (object instanceof BookingTimeSlots) {
BookingTimeSlots o = (BookingTimeSlots) object;
return getStringKey(o.getTimeSlotId());
} else {
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "object {0} is of type {1}; expected type: {2}", new Object[]{object, object.getClass().getName(), BookingTimeSlots.class.getName()});
return null;
}
}
}
也许我错过了什么。如果有人能突出,会非常高兴。 请帮助我!!