Jsf 如何向日历输入中添加日、月或年

Jsf 如何向日历输入中添加日、月或年,jsf,primefaces,Jsf,Primefaces,我在.xhtml文件中有以下代码 <!-- /row --> <div class="row" id="penaltyStartingDate" style="margin-top: 15px"> <div class="span8"> <div class="control-group"> <label class="hcg-control-label span

我在.xhtml文件中有以下代码

<!-- /row -->
    <div class="row" id="penaltyStartingDate" style="margin-top: 15px">
        <div class="span8">
            <div class="control-group">
                <label class="hcg-control-label span5">Ημερομηνία Έναρξης Ισχύος Ποινής</label>
                <div class="controls span7">
                    <p:calendar id="penaltyStartingDate" styleClass="hcg-full-width cursor-pointer" pattern="dd/MM/yyyy"
                                value="#{penaltiesView.penalty.penaltyStartingDate}" />
                    <i class="fa fa-calendar hcg-input-icon"></i>
                </div>
            </div>
        </div>
        <!-- /span -->
    </div>
    <!-- /row -->
    <div id="forfeitureDurationContainer" class="row" style="margin-top: 15px">
        <div class="span8">
            <div class="control-group">
                <label class="hcg-control-label span5">Χρόνος Στέρησης</label>
                <div class="controls span7">
                    <p:inputText id="ForfeitureDurationValue" styleClass="hcg-full-width" value="#{penaltiesView.penalty.forfeitureDurationValue}" disabled="#{!penaltiesView.canEdit()}" style="width:30%" required="false" requiredMessage="Ο χρόνος στέρησης είναι υποχρεωτικός." />
                    <p:selectOneMenu id="ForfeitureDurationType" value="#{penaltiesView.penalty.forfeitureDurationType}" disabled="#{!penaltiesView.canEdit()}" styleClass="margin-bottom-10" style="width:70%">
                        <f:selectItem itemLabel="Μήνες" itemValue="Months" />
                        <f:selectItem itemLabel="Ημέρες" itemValue="Days" />
                        <f:selectItem itemLabel="Χρόνια" itemValue="Years" />
                    </p:selectOneMenu>
                </div>
            </div>
        </div>
        <!-- /span -->
    </div>
    <!-- /row -->
    <div class="row" id="penaltyStopDate" style="margin-top: 15px">
        <div class="span8">
            <div class="control-group">
                <label class="hcg-control-label span5">Ημερομηνία Παύσης Ισχύος Ποινής</label>
                <div class="controls span7">
                    <p:calendar id="penaltyStopDate" styleClass="hcg-full-width cursor-pointer" pattern="dd/MM/yyyy" disabled="true"
                                value="#{penaltiesView.penalty.penaltyStopDate}" />
                    <i class="fa fa-calendar hcg-input-icon"></i>
                </div>
            </div>
        </div>
        <!-- /span -->
    </div>

Ημερομηνία Έναρξης Ισχύος Ποινής
Χρόνος Στέρησης
Ημερομηνία Παύσης Ισχύος Ποινής
这就是它在网页中生成的内容

第一个字段是primefaces日历。下一个是一个字段,您可以在其中输入一个数字,然后从下拉菜单中选择(包括天、月、年),计算出的日期必须出现在我已禁用的最后一个字段中。因此,例如,如果我添加2020年6月1日,然后键入2并选择“天(Ημέρες)”选项,则最后一个字段中必须显示日期为2020年6月3日


你能帮我做这个吗?非常感谢。

您可以通过日历来实现。在
selectOneMenu
中添加ajax:

<p:selectOneMenu id="ForfeitureDurationType" value="#{penaltiesView.penalty.forfeitureDurationType}" 
                 disabled="#{!penaltiesView.canEdit()}" styleClass="margin-bottom-10" style="width:70%">
                        <p:ajax event="change" listener="#{penaltiesView.calculatePenalty()}"
process="penaltyStartingDate,ForfeitureDurationValue,ForfeitureDurationType"/>
                        <f:selectItem itemLabel="Μήνες" itemValue="Months" />
                        <f:selectItem itemLabel="Ημέρες" itemValue="Days" />
                        <f:selectItem itemLabel="Χρόνια" itemValue="Years" />
                    </p:selectOneMenu>

您可以通过日历来实现。在
selectOneMenu
中添加ajax:

<p:selectOneMenu id="ForfeitureDurationType" value="#{penaltiesView.penalty.forfeitureDurationType}" 
                 disabled="#{!penaltiesView.canEdit()}" styleClass="margin-bottom-10" style="width:70%">
                        <p:ajax event="change" listener="#{penaltiesView.calculatePenalty()}"
process="penaltyStartingDate,ForfeitureDurationValue,ForfeitureDurationType"/>
                        <f:selectItem itemLabel="Μήνες" itemValue="Months" />
                        <f:selectItem itemLabel="Ημέρες" itemValue="Days" />
                        <f:selectItem itemLabel="Χρόνια" itemValue="Years" />
                    </p:selectOneMenu>

不幸的是,我得到了一个NullPointerException。错误(com.liferay.faces.bridge.context.internal.ExceptionHandlerAjaxImpl.java:71).handle-/views/popults/_form.xhtml@231,88 listener=“#{penaltiesView.calculatePenalty()}”:java.lang.nullpointerExceptional所以,我认为这是错误的,我应该更改它的值(第二个禁用的日历输入):value=”#{penaltiesView.Penal.penaltyStopDate}“您在页面加载时获得NPE?否。当我从下拉菜单中选择一个选项时。是否调用了侦听器?能否将日志放入方法中?不幸的是,我获得了NullPointerException.ERROR(com.liferay.faces.bridge.context.internal.ExceptionHandleraXimpl.java:71).handle-/views/penals/_form.xhtml@231,88 listener=“#{penaltiesView.calculatePenalty()}”:java.lang.nullpointerExceptional所以,我认为这是错误的,我应该更改它的值(第二个禁用的日历输入):value=“#{penaltiesView.pulture.penaltyStopDate}”你在页面加载时获得NPE?否。当我从下拉菜单中选择一个选项时。是否调用了侦听器?你能将日志放入该方法中吗?