【发布时间】:2017-12-24 10:37:20
【问题描述】:
我对 Primefaces 的工作逻辑还有一个误解。
目前<p:calendar> 组件在我按下提交按钮时无法设置选定日期。
我看到它成功进入 actionListener 方法,但那里的日期值为空。
首先,我尝试使用标准 PF example 创建我的日历。它看起来太简单了,我认为当用户选择日期或提交表单时,组件应该调用 value setter。但它既没有在第一种情况下也没有在第二种情况下这样做。 嗯,我打开谷歌,发现了几个帖子:
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íguez 没有。它不是。我检查了 NetBeans 输出,发现只有“创建组件”之类的 Fine 和 Finest 消息
-
顺便说一下,我还检查了位于同一页面中的输入字段是否正确提交。我可以在调试模式下看到 java 字段具有正确的值。
-
territoryFormBean的范围是什么? -
@XtremeBiker,最初 bean 是 ViewScoped。我尝试将其更改为 SessionScoped,但没有成功
标签: jsf primefaces calendar