我希望用户在使用p:cellEditor进行编辑时限制在p:calander中选择过去的日期(即当前日期之前)
<p:column style="width:120px;" sortBy="#{v.promoDate}" headerText="Action Date">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{v.promoDateString}" />
</f:facet>
<f:facet name="input">
<p:calendar readonlyInput="true" value="#{v.promoDate}" pattern="MMM dd, yyyy" />
</f:facet>
</p:cellEditor>
</p:column>
Bean onEdit方法
public void onEdit(RowEditEvent event) {
setEditMode(true);
foodPromoDTO = (FoodPromotionDTO) event.getObject();
Map<String, Object> sessMap = CommonUtil.getSessionMap();
SessionDTO sessionDTO = (SessionDTO) sessMap.get(WebConstants.SESSION_DTO);
String eid = sessionDTO.getUserDetailsDTO().getEid();
Integer roleCountryId = sessionDTO.getLoggedinUserRoleCountryId();
getDashboardService().addFoodPromotion(foodPromoDTO, eid, editMode, roleCountryId, sessionDTO.getLoggedinCountryCode());
myFoodList = getFoodPromoList();
}
答案 0 :(得分:2)
以下示例代码可以满足您的需求:
视图
<p:growl autoUpdate="true" showDetail="true" />
<h:form id="mainForm">
<p:dataTable value="#{celleditionMBean.list}" var="item" editable="true" editMode="cell" widgetVar="dtVar">
<p:ajax event="cellEdit" listener="#{celleditionMBean.onEdit}" process="date" />
<p:column style="width:120px;" headerText="Action Date">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{item.promoDate}" >
<f:convertDateTime dateStyle="date" pattern="MM dd, yyyy" />
</h:outputText>
</f:facet>
<f:facet name="input">
<p:calendar id="date" readonlyInput="true" value="#{item.promoDate}" pattern="MM dd, yyyy" mindate="#{celleditionMBean.current}" />
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</h:form>
受管Bean :
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.CellEditEvent;
@ManagedBean
@ViewScoped
public class CelleditionMBean implements Serializable {
private List<SimpleBean> list;
private Date current;
@PostConstruct
public void setup() {
current = new Date();
list = new ArrayList<SimpleBean>();
list.add(new SimpleBean(11, "A"));
list.add(new SimpleBean(22, "B"));
list.add(new SimpleBean(33, "C"));
}
public void onEdit(CellEditEvent event) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Changed");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public List<SimpleBean> getList() {
return list;
}
public void setList(List<SimpleBean> list) {
this.list = list;
}
public Date getCurrent() {
return current;
}
public void setCurrent(Date current) {
this.current = current;
}
}