Jsf 从另一个xhtml文件按id更新xhtml文件中的表单

Jsf 从另一个xhtml文件按id更新xhtml文件中的表单,jsf,primefaces,jsf-2,popup,xhtml,Jsf,Primefaces,Jsf 2,Popup,Xhtml,这是我的密码 index.xhtml <h1>Student List</h1> <h:form id="studentListForm"> <h:dataTable id="studentsList" style="border:2px solid;" var="student" value="#{tab

这是我的密码

index.xhtml

<h1>Student List</h1>
    <h:form id="studentListForm">
        <h:dataTable id="studentsList"
                     style="border:2px solid;"
                     var="student"
                     value="#{tableItems.students}">
            <h:column>
                <f:facet name="First Name"/>
                <h:outputText value="#{student.firstName}"/>
            </h:column>
            <h:column>
                <f:facet name="Last Name"/>
                <h:outputText value="#{student.lastName}"/>
            </h:column>
            <h:column>
                <f:facet name="Faculty Name"/>
                <h:outputText value="#{student.faculty.name}"/>
            </h:column>
        </h:dataTable>
        <br/>
        <p:commandButton value="Add Student"
                         update=":studentAdding"
                         oncomplete="PF('studentAddingDialog').show();"/>
    </h:form>
学生名单

addStudent.xhtml

<p:dialog id="studentAddingDialogId" modal="true"
              header="Add Student"
              widgetVar="studentAddingDialog"
              closeOnEscape="true">

        <h:form id="studentAdding">
            <h:outputLabel value="Student first name"/>
            <h:inputText id="firstName"
                         value="#{tableItems.studentFirstName}"
                         required="true"/>
            <br/>
            <h:outputLabel value="Student last name"/>
            <h:inputText id="lastName"
                         value="#{tableItems.studentLastName}"
                         required="true"/>
            <br/>
            <h:outputLabel value="Choose student faculty"/>
            <h:selectOneMenu id="selectFaculty"
                             value="#{tableItems.studentFaculty}"
                             required="true">

                <f:selectItem itemLabel="--Select--" itemValue=""/>
                <f:selectItems value="#{faculties.faculties}"
                               var="itam"
                               itemValue="#{itam.name}"
                               itemLabel="#{itam.name}"/>
            </h:selectOneMenu>
            <p:commandButton value="Submit"
                             actionListener="#{tableItems.addStudent}"
                             oncomplete="PF('studentAddingDialog').hide();"
                             update="studentListForm"/>
        </h:form>
    </p:dialog>



运行程序后,我看到一个错误(HTTP状态500-找不到表达式的组件):studentAdding“引用自”studentListForm:j_idt10“
为什么它无法从另一个xhtml文件中识别id为的表单?

这里您试图打开位于另一个页面中的对话框,因此当您尝试更新
studentAdding
时,它找不到表单,这解释了从中引用的
找不到表达式的组件:studentAdding”的错误“studentListForm:j_idt10”
,我建议您在主页中添加
addStudent.xhtml
,即
index.xhtml

<ui:include src="/../studentAdding.xhtml">
    <ui:param name="updateForm" value=":studentListForm"/>
</ui:include>

要使用包含的xhtml文件中的任何xhtml元素,可以将其作为
传递。它允许您使用包含的源文件中的此特定元素:

<ui:include src="/../studentAdding.xhtml">
    <ui:param name="yourElementAlias" value=":pathTo:Element"/>
</ui:include>

然后,要在studentAdding.xhtml中使用此元素(例如更新它),请执行以下操作:

<p:commandButton value="Submit"
             actionListener="#{tableItems.addStudent}"
             oncomplete="PF('studentAddingDialog').hide();"
             update="#{yourElementAlias}"/>

<p:commandButton value="Submit"
             actionListener="#{tableItems.addStudent}"
             oncomplete="PF('studentAddingDialog').hide();"
             update="#{yourElementAlias}"/>