【发布时间】:2015-09-09 00:08:03
【问题描述】:
在表格上,我有一些个人信息(姓名、地址等)和一个 changeListener,它根据性别和姓氏更新称呼和字母称呼。如果底层实体已经存储在数据库中,它可以正常工作。如果我正在为新的(未保存的)条目输入数据,则在调用侦听器后表单会重置。输入的所有数据都丢失了,只保留了我在听众中修改的称呼、字母称呼和性别、我使用的姓名并附加了一个 ajax 调用。
这是表格的一部分:
<h:form id="person">
<p:panel header="#{msg['prs']}">
<h:panelGrid columns="6" cellpadding="4">
<h:outputText value="#{msg['prs.salutation']}"/>
<p:inputText value="#{personBean.selectedPerson.salutation}"/>
<h:outputText value="#{msg['prs.lettersalutation']}"/>
<p:inputText value="#{personBean.selectedPerson.letterSalutation}"/>
<p:spacer/><p:spacer/>
<h:outputText value="#{msg['prs.name']}: "/>
<p:inputText value="#{personBean.selectedPerson.name}">
<p:ajax event="change" update="person"
listener="#{personBean.selectedPerson.updateSalutation}" />
</p:inputText>
<h:outputText value="#{msg['prs.surname']}: "/>
<p:inputText value="#{personBean.selectedPerson.surname}"/>
<h:outputText value="#{msg['prs.gender']}: "/>
<p:selectOneMenu value="#{personBean.selectedPerson.gender}">
<f:selectItems value="#{enumHelper.getEnum('Gender')}"/>
<p:ajax event="change" update="person"
listener="#{personBean.selectedPerson.updateSalutation}" />
</p:selectOneMenu>
</p:panel>
</h:form>
在我做的代码中,然后更新。
public void updateSalutation() {
// simplified
letterSalutation = "...";
salutation = "...";
// outputs for debug
System.out.println(this.getName()); // --> not null
System.out.println(this.getSurname()); // --> null
}
即使在此处输入了数据,未附加到 ajax 调用的已在此调用姓氏为 null。对于所有其他领域也是如此。在我的应用程序中,我使用 Primefaces、JavaEE 1.6 和 Wildfly。
这种行为的原因是什么?为了防止这种情况发生,我可以在通话中进行哪些更改?
【问题讨论】:
标签: ajax jsf-2 primefaces