我想在用户点击上下文菜单时更新<p:dataTable>
中的所选行(对象),但绑定到<p:dataTable>
selection=""
的对象不会根据更新行选择/上下文菜单单击,调试显示bean中对象的属性不包含任何更新的值但为空。
代码是:
<h:form id="searchStdentsFrm">
<p:dialog id="searchStdentsDlg" header="Search Students" widgetVar="srchStdents" modal="true">
<p:contextMenu for="srchStdentsTble" id="menuStdEdit">
<p:menuitem value="Change Status" update="stdDetail" icon="ui-icon-flag" oncomplete="PF('editStudentDialog').show()" />
<p:menuitem value="Edit Student" update="stdStatusDetail" icon="ui-icon-wrench" oncomplete="PF('editStudentStatusDialog').show()" action="#{viewStudentsBean.testAction}"/>
</p:contextMenu>
<p:dataTable id="srchStdentsTble" var="student" value="#{viewStudentsBean.studentsList}"
rowKey="#{student.id}" selection="#{viewStudentsBean.selectedStudent}"
selectionMode="single" widgetVar="srchStdentTbl"
emptyMessage="No students found with the given criteria" filteredValue="#{viewStudentsBean.filteredStudents}">
<p:ajax event="contextMenu"/>
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search Students:" />
<p:inputText id="globalFilter" onkeyup="PF('srchStdentTbl').filter()" style="width:200px" placeholder="Enter keyword"/>
</p:outputPanel>
</f:facet>
<p:column id="stdentId" headerText="Id" filterBy="#{student.id}" filterStyle="display:none">
<h:outputText value="#{student.id}" />
</p:column>
<p:column id="stdentFirstName" headerText="Firstname" filterBy="#{student.firstName}" filterStyle="display:none">
<h:outputText value="#{student.firstName}" />
</p:column>
<p:column id="stdentLastname" headerText="Lastname" filterBy="#{student.lastName}" filterStyle="display:none">
<h:outputText value="#{student.lastName}" />
</p:column>
<p:column id="stdentFathername" headerText="Father name" filterBy="#{student.fatherName}" filterStyle="display:none">
<h:outputText value="#{student.fatherName}" />
</p:column>
<p:column id="stdentGender" headerText="Gender" filterBy="#{student.gender}" filterStyle="display:none">
<h:outputText value="#{student.gender}" />
</p:column>
<p:column id="stdentDOB" headerText="Date Of birth" filterBy="#{student.dob}" filterStyle="display:none">
<h:outputText value="#{student.dob}" />
</p:column>
<p:column id="stdentSkype" headerText="Skype/Email" filterBy="#{student.skypeOrEmailId}" filterStyle="display:none">
<h:outputText value="#{student.skypeOrEmailId}" />
</p:column>
<p:column id="stdentPhone" headerText="Phone No" filterBy="#{student.phoneNumber}" filterStyle="display:none">
<h:outputText value="#{student.phoneNumber}" />
</p:column>
<p:column id="stdentAddrs" headerText="Address" filterBy="#{student.address}" filterStyle="display:none">
<h:outputText value="#{student.address}" />
</p:column>
<p:column id="stdentCountry" headerText="Country" filterBy="#{student.country}" filterStyle="display:none">
<h:outputText value="#{student.country}" />
</p:column>
<p:column id="stdentJOD" headerText="Joining Date" filterBy="#{student.dateOfJoining}" filterStyle="display:none">
<h:outputText value="#{student.dateOfJoining}" />
</p:column>
<p:column id="stdentGenralRmrks" headerText="General Remarks" filterBy="#{student.generalRemarks}" filterStyle="display:none">
<h:outputText value="#{student.generalRemarks}" />
</p:column>
<p:column id="studentStatus" headerText="Student Status" filterBy="#{student.studentStatus}" filterStyle="display:none">
<h:outputText value="#{student.studentStatus}" />
</p:column>
</p:dataTable>
</p:dialog>
<p:dialog id="editStdentDlg" header="Edit Student" widgetVar="editStudentDialog" modal="true">
<p:outputPanel id="stdDetail" style="text-align:center;">
<p:outputLabel value="First Name *" />
<p:inputText value="#{viewStudentsBean.selectedStudent.lastName}"/>
<p:panelGrid id="editStdPanelGrd" columns="2" cellpadding="5" style="width: 100%;">
<p:outputLabel value="First Name *" />
<p:inputText id="stdEditFname" value="#{viewStudentsBean.selectedStudent.firstName}"/>
<p:outputLabel value="Last Name *" />
<p:inputText id="stdEditLastname" value="#{viewStudentsBean.selectedStudent.lastName}"/>
<p:outputLabel value="Father's Name *" />
<p:inputText id="stdEditFathName" value="#{viewStudentsBean.selectedStudent.fatherName}"/>
<p:outputLabel value="Gender *" />
<h:selectOneMenu id="stdEditGnder" value="#{viewStudentsBean.selectedStudent.gender}">
<f:selectItem itemValue="Male" itemLabel="Male" />
<f:selectItem itemValue="Female" itemLabel="Female" />
</h:selectOneMenu>
<p:outputLabel value="Date Of Birth *" />
<p:calendar id="stdEditDOB" value="#{viewStudentsBean.selectedStudent.dob}"/>
<p:outputLabel value="Skype Id/Email *" />
<p:inputText id="stdEditSkype" value="#{viewStudentsBean.selectedStudent.skypeOrEmailId}"/>
<p:outputLabel value="Phone No *" />
<p:inputText id="stdEditPNo" value="#{viewStudentsBean.selectedStudent.phoneNumber}"/>
<p:outputLabel value="Address *" />
<p:inputText id="stdEditAddrs" value="#{viewStudentsBean.selectedStudent.address}"/>
<p:outputLabel value="Country *" />
<p:inputText id="stdEditCountry" value="#{viewStudentsBean.selectedStudent.country}"/>
<p:outputLabel value="Date of joining *" />
<p:calendar id="stdEditDOJ" value="#{viewStudentsBean.selectedStudent.dateOfJoining}"/>
<p:outputLabel value="General Remarks" />
<p:inputText id="stdEditGR" value="#{viewStudentsBean.selectedStudent.generalRemarks}"/>
</p:panelGrid>
</p:outputPanel>
</p:dialog>
<p:dialog id="editStdentStatusDlg" header="Edit Student" widgetVar="editStudentStatusDialog" modal="true">
<p:outputPanel id="stdStatusDetail" style="text-align:center;">
The current status of:<p:outputLabel value="#{viewStudentsBean.selectedStudent.lastName}"/>
is: <p:outputLabel value="#{viewStudentsBean.selectedStudent.studentStatus}" />
</p:outputPanel>
</p:dialog>
</h:form>
PS:我正在使用PrimeFaces 5.0的JSF 2.2
我绝对被困在这里。任何帮助将不胜感激
答案 0 :(得分:0)
找到解决方案。实际上我想要显示/编辑绑定到p:datatable的选择对象的第二个对话框需要在上下文菜单中更新,如:
update=":searchStdentsForm:editStdentDlg"
表示需要明确引用的表单和对话框。