p:ajax无法更新p:inputText [英] p:ajax not updating p:inputText
问题描述
我无法根据使用<p:ajax>
在另一个<p:inputText>
中输入的值来更新<p:inputText>
.我将JSF 2与PrimeFaces 5一起使用.第二个<p:inputText>
未更新,与<p:ajax>
相关联的侦听器被调用,并且我在侦听器中获取了正确的值,但未在视图上更新.
I am unable to update a <p:inputText>
based on the value entered in another <p:inputText>
using <p:ajax>
. I am using JSF 2 with PrimeFaces 5. The second <p:inputText>
is not updating, the listener associated with <p:ajax>
is being called and i am getting the correct values in the listener but its not updated on the view.
查看代码为:
<p:dialog id="newStdDlg" header="Add new Student" widgetVar="newStdDlg" modal="true">
<h:panelGrid id="newStdDlgPanel" columns="2" cellpadding="5" style="width:100%;">
<p:outputLabel value="First Name *" />
<p:inputText id="studentfname" value="#{addStudentBean.student.firstName}">
<p:ajax event="change" update="studentUsrname" listener="#{addStudentBean.firstNameChange}" />
</p:inputText>
<p:outputLabel value="Last Name *" />
<p:inputText value="#{addStudentBean.student.lastName}"/>
<p:outputLabel value="Father's Name *" />
<p:inputText value="#{addStudentBean.student.fatherName}"/>
<p:outputLabel id="uLbl" value="Username (System Generated) *" />
<p:inputText id="studentUsrname" value="#{addStudentBean.student.user.username}" />
<p:outputLabel value="This temporary password would be mailed to user: " />
<p:outputLabel id="stdpassword" value="#{addStudentBean.student.user.password}"/>
</h:panelGrid>
<p:commandButton value="Create Student"
actionListener="#{addStudentBean.addNewStudentAction}"
style="margin-left:auto;margin-right:auto;display:block;"/>
</p:dialog>
,会话作用域托管bean的侦听器是:
and the listener of the session scoped managed bean is :
public void firstNameChange() {
System.out.println("In AddStudentBean().firstNameChange()..........");
System.out.println("The value of student.getFirstName: "+student.getFirstName());
System.out.println("updating system generated username as: "+student.getFirstName()+String.valueOf(new UserDAO().getUserCount()+1));
student.getUser().setUsername(student.getFirstName()+String.valueOf(new UserDAO().getUserCount()+1));
student.getUser().setPassword(KaaloUtils.getPassword());
}
推荐答案
就像Jaqen在注释中提到的,注释使用对话框内的h:form
.
Like Jaqen mentioned in comments the comments use h:form
inside dialog.
如果要从ManagedBean更新组件,可以使用org.primefaces.RequestContext
的update
方法来完成.
If you want to update the component from ManagedBean you can do that by using org.primefaces.RequestContext
's update
method.
RequestContext.getCurrentInstance().update("COMPONENT_ID_TO_UPDATE")
如果您觉得此方法过于内聚,则只能从Facelet更新,请确保不要将p:dialog
放在h:from
中,而不要在p:dialog
中使用h:form
.
If you feel like this method is too Cohesive, you can update from Facelet only, make sure remember to not place p:dialog
in a h:from
instead use h:form
inside p:dialog
.
这篇关于p:ajax无法更新p:inputText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!