这应该很简单,但我只是遗漏了一些东西。我的PrimeFaces日历字段没有调用setter方法。显示页面时会调用getter,但永远不会调用setter。
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:form id="timeframeTabForm">
<div style="position:relative; left:85%;">
<p:commandLink id="explainTimeframeTabId" style="text-decoration:underline;" value="#{i18n['help-text-tab-label']}"
onclick="PF('timeframeTabDialogVar').show()"/>
</div>
<p:selectOneRadio id="searchTimeframe" layout="custom" value="#{articleSearchFormBean.timeframe}">
<f:selectItem itemValue="#{i18n['timeframe-last-1-hour-label']}" />
<f:selectItem itemValue="#{i18n['timeframe-last-3-days-label']}" />
<f:selectItem itemValue="#{i18n['timeframe-last-1-year-label']}" />
<f:selectItem itemValue="#{i18n['timeframe-last-12-hours-label']}" />
<f:selectItem itemValue="#{i18n['timeframe-last-7-days-label']}" />
<f:selectItem itemValue="#{i18n['timeframe-last-2-years-label']}" />
<f:selectItem itemValue="#{i18n['timeframe-last-24-hours-label']}" />
<f:selectItem itemValue="#{i18n['timeframe-last-30-days-label']}" />
<f:selectItem itemValue="#{i18n['timeframe-last-3-years-label']}" />
<f:selectItem itemValue="#{i18n['timeframe-last-90-days-label']}" />
<f:selectItem itemValue="#{i18n['timeframe-specify-dates-label']}" />
<f:selectItem itemValue="#{i18n['timeframe-last-180-days-label']}" />
<p:ajax />
</p:selectOneRadio>
<h:panelGrid columns="3" cellspacing="15">
<h:panelGrid columns="2" cellspacing="5">
<p:radioButton id="timeframeOpt0" for="searchTimeframe" itemIndex="0"
onchange="document.getElementById('_listenerportlet_WAR_listenerportlet_:articleSearchForm:tabView:timeframeChecked').innerHTML = '(#{i18n['timeframe-last-1-hour-label']})';" />
<h:outputLabel value="#{i18n['timeframe-last-1-hour-label']}" style="padding-left:10px;" />
</h:panelGrid>
<h:panelGrid columns="2" cellspacing="5">
<p:radioButton id="timeframeOpt1" for="searchTimeframe" itemIndex="1" style="padding-left:30px;"
onchange="document.getElementById('_listenerportlet_WAR_listenerportlet_:articleSearchForm:tabView:timeframeChecked').innerHTML = '(#{i18n['timeframe-last-3-days-label']})';" />
<h:outputLabel value="#{i18n['timeframe-last-3-days-label']}" style="padding-left:10px;" />
</h:panelGrid>
<h:panelGrid columns="2" cellspacing="5">
<p:radioButton id="timeframeOpt2" for="searchTimeframe" itemIndex="2" style="padding-left:30px;"
onchange="document.getElementById('_listenerportlet_WAR_listenerportlet_:articleSearchForm:tabView:timeframeChecked').innerHTML = '(#{i18n['timeframe-last-1-year-label']})';" />
<h:outputLabel value="#{i18n['timeframe-last-1-year-label']}" style="padding-left:10px;" />
</h:panelGrid>
<h:panelGrid columns="2" cellspacing="5">
<p:radioButton id="timeframeOpt3" for="searchTimeframe" itemIndex="3"
onchange="document.getElementById('_listenerportlet_WAR_listenerportlet_:articleSearchForm:tabView:timeframeChecked').innerHTML = '(#{i18n['timeframe-last-12-hours-label']})';" />
<h:outputLabel value="#{i18n['timeframe-last-12-hours-label']}" style="padding-left:10px;" />
</h:panelGrid>
<h:panelGrid columns="2" cellspacing="5">
<p:radioButton id="timeframeOpt4" for="searchTimeframe" itemIndex="4" style="padding-left:30px;"
onchange="document.getElementById('_listenerportlet_WAR_listenerportlet_:articleSearchForm:tabView:timeframeChecked').innerHTML = '(#{i18n['timeframe-last-7-days-label']})';" />
<h:outputLabel value="#{i18n['timeframe-last-7-days-label']}" style="padding-left:10px;" />
</h:panelGrid>
<h:panelGrid columns="2" cellspacing="5">
<p:radioButton id="timeframeOpt5" for="searchTimeframe" itemIndex="5" style="padding-left:30px;"
onchange="document.getElementById('_listenerportlet_WAR_listenerportlet_:articleSearchForm:tabView:timeframeChecked').innerHTML = '(#{i18n['timeframe-last-2-years-label']})';" />
<h:outputLabel value="#{i18n['timeframe-last-2-years-label']}" style="padding-left:10px;" />
</h:panelGrid>
<h:panelGrid columns="2" cellspacing="5">
<p:radioButton id="timeframeOpt6" for="searchTimeframe" itemIndex="6"
onchange="document.getElementById('_listenerportlet_WAR_listenerportlet_:articleSearchForm:tabView:timeframeChecked').innerHTML = '(#{i18n['timeframe-last-24-hours-label']})';" />
<h:outputLabel value="#{i18n['timeframe-last-24-hours-label']}" style="padding-left:10px;" />
</h:panelGrid>
<h:panelGrid columns="2" cellspacing="5">
<p:radioButton id="timeframeOpt7" for="searchTimeframe" itemIndex="7" style="padding-left:30px;"
onchange="document.getElementById('_listenerportlet_WAR_listenerportlet_:articleSearchForm:tabView:timeframeChecked').innerHTML = '(#{i18n['timeframe-last-30-days-label']})';" />
<h:outputLabel value="#{i18n['timeframe-last-30-days-label']}" style="padding-left:10px;" />
</h:panelGrid>
<h:panelGrid columns="2" cellspacing="5">
<p:radioButton id="timeframeOpt8" for="searchTimeframe" itemIndex="8" style="padding-left:30px;"
onchange="document.getElementById('_listenerportlet_WAR_listenerportlet_:articleSearchForm:tabView:timeframeChecked').innerHTML = '(#{i18n['timeframe-last-3-years-label']})';" />
<h:outputLabel value="#{i18n['timeframe-last-3-years-label']}" style="padding-left:10px;" />
</h:panelGrid>
<h:outputText value=" " />
<h:panelGrid columns="2" cellspacing="5">
<p:radioButton id="timeframeOpt9" for="searchTimeframe" itemIndex="9" style="padding-left:30px;"
onchange="document.getElementById('_listenerportlet_WAR_listenerportlet_:articleSearchForm:tabView:timeframeChecked').innerHTML = '(#{i18n['timeframe-last-90-days-label']})';" />
<h:outputLabel value="#{i18n['timeframe-last-90-days-label']}" style="padding-left:10px;" />
</h:panelGrid>
<h:panelGrid columns="4" cellspacing="5">
<p:radioButton id="timeframeOpt10" for="searchTimeframe" itemIndex="10" style="padding-left:30px;"
onchange="document.getElementById('_listenerportlet_WAR_listenerportlet_:articleSearchForm:tabView:timeframeChecked').innerHTML = '(#{i18n['timeframe-specify-dates-label']})';" />
<h:outputLabel value="#{i18n['timeframe-specify-dates-label']}" style="padding-left:10px;" />
<h:panelGrid columns="2" style="align-content:center;">
<p:outputLabel value="#{i18n['timeframe-dates-start-label']}" />
<h:outputText value=" " />
<p:calendar id="timeframeStartButton" value="#{articleSearchFormBean.timeframeStart}" showOn="button" />
</h:panelGrid>
<h:panelGrid columns="2">
<h:outputText value="#{i18n['timeframe-dates-end-label']}" />
<h:outputText value=" " />
<p:calendar id="timeframeEndButton" value="#{articleSearchFormBean.timeframeEnd}" showOn="button" />
</h:panelGrid>
</h:panelGrid>
<h:outputText value=" " />
<h:panelGrid columns="2" cellspacing="5">
<p:radioButton id="timeframeOpt11" for="searchTimeframe" itemIndex="11" style="padding-left:30px;"
onchange="document.getElementById('_listenerportlet_WAR_listenerportlet_:articleSearchForm:tabView:timeframeChecked').innerHTML = '(#{i18n['timeframe-last-180-days-label']})';" />
<h:outputLabel value="#{i18n['timeframe-last-180-days-label']}" style="padding-left:10px;" />
</h:panelGrid>
<h:outputText value=" " />
</h:panelGrid>
</h:form>
<h:form id="timeframeTabButtonForm">
<p:commandButton id='clear' value="#{i18n['tab-clear-button-label']}"
update=":#{component.namingContainer.parent.namingContainer.clientId}"
action="#{listenerArticleSearchFormController.clearTimeframeTabButtonListener}" process="@this"/>
</h:form>
<p:dialog header="Timeframe Tab Explained" widgetVar="timeframeTabDialogVar">
<h:outputText value="#{i18n['timeframe-tab-description']}" />
</p:dialog>
getter和setter方法的片段如下。
public Date getTimeframeStart() {
return timeframeStart;
}
public void setTimeframeStart(Date timeframeStart) {
this.timeframeStart = timeframeStart;
}
public Date getTimeframeEnd() {
return timeframeEnd;
}
public void setTimeframeEnd(Date timeframeEnd) {
this.timeframeEnd = timeframeEnd;
}
单选按钮一切正常并且正在进入后端,但由于某种原因,日历字段不是。
我正在使用PrimeFaces 5.0
谢谢
答案 0 :(得分:0)
如何添加<p:ajax>
?
即
<p:calendar id="timeframeEndButton" value="#{articleSearchFormBean.timeframeEnd}" showOn="button" >
<p:ajax event="dateSelect" process="@this"/>
</p:calendar>
答案 1 :(得分:0)
如果你点击提交按钮并且验证是正确的,它将被调用,primefaces日历也可以工作。您可以测试它,删除/注释网页中的所有代码,只放置日历并尝试提交,并在托管bean上直接输出值,然后逐步添加代码并在每个步骤中进行测试。