限制在使用P:Celleditor编辑时选择过去的日期:Calander



我希望用户在使用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();
}

这是一个示例代码,它可以做到您需要的:

视图

<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;
    }
}

最新更新