简体   繁体   English

p:ajax无法更新p:inputText

[英]p:ajax not updating p:inputText

I am unable to update a <p:inputText> based on the value entered in another <p:inputText> using <p:ajax> . 我无法根据使用<p:ajax>在另一个<p:inputText>输入的值来更新<p:inputText> <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. 我正在将JSF 2与PrimeFaces 5一起使用。第二个<p:inputText>未更新,与<p:ajax>关联的侦听器被调用,并且我在侦听器中获取了正确的值,但未在视图上更新。

the view code is: 视图代码是:

<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>

and the listener of the session scoped managed bean is : 会话范围的托管bean的侦听器是:

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());
}

Like Jaqen mentioned in comments the comments use h:form inside dialog. 就像Jaqen在评论中提到的那样,评论在对话框内使用h:form

If you want to update the component from ManagedBean you can do that by using org.primefaces.RequestContext 's update method. 如果要从ManagedBean更新组件,可以使用org.primefaces.RequestContextupdate方法来完成。

RequestContext.getCurrentInstance().update("COMPONENT_ID_TO_UPDATE")

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 . 如果您觉得此方法太缺乏凝聚力,则只能从Facelet更新,请确保不要将p:dialog放在h:from而应在p:dialog使用h:form

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM