我對Primefaces的工作邏輯還有一個誤解。Primefaces日曆沒有設置日期
現在<p:calendar>
當我按下提交按鈕時,組件不能設置選定的日期。
我看到它已成功進入actionListener方法,但日期值爲空。
首先,我嘗試使用標準PF example創建我的日曆。它看起來太簡單了,我認爲在用戶選擇日期或提交表單時,組件應該調用值設置器。但是它在第一個和第二個案例中都沒有做到。 好了,我打開谷歌和發現了幾個帖子:
Primefaces Calendar Setting Date Value in Backing Bean
p:calendar value not set in backing bean
我保證,我的日曆位於<h:form></h:form>
標籤之間。另外我試着加入process="@this"
和process=":beginDateForm :endDateForm @this"
,其中beginDateForm和endDateForm是包含<p:calendar>
組件的表單。
此外,我發現post,並試圖創造SelectEvent監聽方法:
private void changeDate(SelectEvent event) {
beginDate = (Date) event.getObject();
}
但沒有成功。
我也嘗試使用valueChangeListener變更日期:
<h:form id="beginDateForm">
<p:calendar id="passBeginDate" valueChangeListener="#{territoryFormBean.changeDate}" mode="popup" readonly="true" pattern="dd.MM.yyyy" showOn="button" value="#{territoryFormBean.beginDate}" />
</h:form>
當然我改變事件ValueChangeEvent。
之後我移動<p:calendar>
和<p:commandButton>
部件到相同<h:form>
並試圖兩個不同的過程值process="passTerrForm:passBeginDate passTerrForm:passEndDate @this"
和process="@form @this"
和process="@form"
在最後一種情況按鈕不會觸發甚至偵聽方法。
我目前的組成部分是:
<p:commandButton value="Search" id="searchPassButton" actionListener="#{territoryFormBean.search}" update=":passTerrForm:territoryTable" process="passTerrForm:passBeginDate passTerrForm:passEndDate @this" partialSubmit="true" />
<p:column>
<p:calendar id="passBeginDate" mode="popup" readonly="true" pattern="dd.MM.yyyy" showOn="button" value="#{territoryFormBean.beginDate}" />
</p:column>
<p:column>
<p:calendar id="passEndDate" mode="popup" readonly="true" pattern="dd.MM.yyyy" showOn="button" value="#{territoryFormBean.endDate}" />
</p:column>
傢伙,你可以請建議別的。或者你可能會看到我的代碼有什麼問題。 我不明白爲什麼組件不會調用setter。
該代碼會引發一些錯誤? –
@PolRodríguezno。它不是。我查了NetBeans輸出,發現只有Fine和Finest的消息有'組件創建' –
順便說一下,我也檢查了位於同一頁面的輸入字段是否正確提交。我可以在調試模式下看到java字段具有正確的值。 –