这个问题的解决方案已经存在于 stackoverflow 中。虽然我已经问过这个问题,但这是因为所有可用的答案都不能解决我的问题/错误。所以我问了这个问题,以便我可以解释我遇到此错误的情况。
文件名:studentDailyAttendanceSchool.xhtml
<p:dataTable id="dtManagePanel" value="#{studentAttendanceSchoolController.studentAttendanceSchoolWrappers[0].studentAttendanceSchoolDtos}" var="studentAttendanceSchoolDto" rowIndexVar="row" tableStyleClass="ui-datatable">
<p:column headerText="S.N">
<h:outputText value="#{row + 1}"/>
</p:column>
<p:column headerText="Full Nam1e">
<h:outputText value="#{studentAttendanceSchoolDto.studentDto.fullName}-#{studentAttendanceSchoolDto.studentDto.usersDto.username}"/>
</p:column>
<p:column headerText="Section">
<h:outputText value="#{studentAttendanceSchoolDto.studentDto.sectionDto.name}"/>
</p:column>
<p:columns value="#{studentAttendanceSchoolController.studentAttendanceSchoolWrappers}" var="studentAttendanceSchoolWrapper" headerText="#{studentAttendanceSchoolWrapper.studentAttendanceSchoolDtos[0].attendanceDate}" columnIndexVar="col">
<f:facet name="header">
<div class="row">
<div class="col-sm-12">
<p:commandButton value="#{studentAttendanceSchoolWrapper.studentAttendanceSchoolDtos[col].holiday?'Unmark As Holiday':'Mark As Holiday'}" styleClass="#{studentAttendanceSchoolWrapper.studentAttendanceSchoolDtos[col].holiday?'btn btn-sm btn-outline-warning':'btn btn-sm btn-outline-primary'}" actionListener="#{studentAttendanceSchoolController.markUnmarkAsHoliday(studentAttendanceSchoolWrapper)}" process="@this" update="frmList:dtManagePanel @this"/>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<p:selectBooleanCheckbox id="sbcbPresentAll" value="#{studentAttendanceSchoolWrapper.transientCheckAll}" styleClass="mt-2" disabled="#{studentAttendanceSchoolWrapper.studentAttendanceSchoolDtos[col].holiday}">
<p:ajax event="valueChange" process="@this" update="frmList:dtManagePanel" listener="#{studentAttendanceSchoolController.onChangeAllPresent(studentAttendanceSchoolWrapper)}"/>
</p:selectBooleanCheckbox>
<p:outputLabel for="sbcbPresentAll" value="Check All" styleClass="ml-2"/>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<p:outputLabel value="#{studentAttendanceSchoolWrapper.studentAttendanceSchoolDtos[col].attendanceDate}"/>
</div>
</div>
</f:facet>
<p:selectBooleanCheckbox title="Is Present" id="sbcbIsPresent" value="#{studentAttendanceSchoolWrapper.studentAttendanceSchoolDtos[row].isPresent}" disabled="#{(studentAttendanceSchoolWrapper.studentAttendanceSchoolDtos[row].isInformed or studentAttendanceSchoolWrapper.studentAttendanceSchoolDtos[row].isLate or studentAttendanceSchoolWrapper.studentAttendanceSchoolDtos[row].holiday)}">
<p:ajax event="valueChange" process="@this" update="sbcbIsInformed"/>
</p:selectBooleanCheckbox>
<p:commandLink id="clCommentMs" oncomplete="PF('opCommentMs').show('#{component.clientId}')" update="frmList:pnlCommentMs" title="Comment" styleClass="ml-2" disabled="#{!(studentAttendanceSchoolWrapper.studentAttendanceSchoolDtos[row].holiday or studentAttendanceSchoolWrapper.studentAttendanceSchoolDtos[row].isInformed or studentAttendanceSchoolWrapper.studentAttendanceSchoolDtos[row].isLate)}">
<p:graphicImage value="images/comment.png" alt="Comment" height="14" width="14"/>
<f:setPropertyActionListener value="#{studentAttendanceSchoolWrapper.studentAttendanceSchoolDtos[row]}" target="#{studentAttendanceSchoolController.studentAttendanceSchoolDto}"/>
</p:commandLink>
<p:selectBooleanCheckbox title="Is Informed" id="sbcbIsInformed" value="#{studentAttendanceSchoolWrapper.studentAttendanceSchoolDtos[row].isInformed}" disabled="#{studentAttendanceSchoolWrapper.studentAttendanceSchoolDtos[row].isPresent or studentAttendanceSchoolWrapper.studentAttendanceSchoolDtos[row].holiday}">
<p:ajax event="valueChange" process="@this" update="sbcbIsPresent clCommentMs frmList:pnlCommentMs" listener="#{studentAttendanceSchoolController.emptyReason(studentAttendanceSchoolWrapper.studentAttendanceSchoolDtos[row])}"/>
</p:selectBooleanCheckbox>
</p:columns>
</p:dataTable>
<p:commandButton id="btnSave" value="Save All" actionListener="#{studentAttendanceSchoolController.saveUpdateAll()}" styleClass="btn btn-sm btn-outline-success" icon="fas fa-save" process="@form">
</p:commandButton>
文件名:StudentAttendanceSchoolController.java
public void search() {
studentAttendanceSchoolWrappers = new ArrayList();
if (searchStudentAttendanceBean.getStudentAttendanceDto().getProgramSemesterDto().getId() != null) {
List<StudentDto> studentDtos = fetchStudents();
List<String> dates = getAttendanceDates();
dates.stream().map((date) -> getStudentAttendanceSchoolWrapper(studentDtos, date)).forEachOrdered((studentAttendanceSchoolWrapper) -> {
studentAttendanceSchoolWrappers.add(studentAttendanceSchoolWrapper);
});
}
}
private StudentAttendanceSchoolWrapper getStudentAttendanceSchoolWrapper(List<StudentDto> studentDtos, String date) {
StudentAttendanceSchoolWrapper studentAttendanceSchoolWrapper = new StudentAttendanceSchoolWrapper();
List<StudentAttendanceSchoolDto> studentAttendanceSchoolDtos = new ArrayList();
studentDtos.forEach((studentDto) -> {
StudentAttendanceSchoolDto studentAttendanceSchoolDtoAlreadyExist = studentAttendanceSchoolService.getByProgramSemesterIdStudentIdAndAttendanceDate(setStudentAttendanceSchoolForSearch(date, studentDto));
if (studentAttendanceSchoolDtoAlreadyExist.getId() != null) {
studentAttendanceSchoolDtos.add(studentAttendanceSchoolDtoAlreadyExist);
} else {
studentAttendanceSchoolDtos.add(setStudentAttendanceSchoolForSearch(date, studentDto));
}
});
studentAttendanceSchoolWrapper.setStudentAttendanceSchoolDtos(studentAttendanceSchoolDtos);
return studentAttendanceSchoolWrapper;
}
private StudentAttendanceSchoolDto setStudentAttendanceSchoolForSearch(String date, StudentDto studentDto) {
StudentAttendanceSchoolDto studentAttendanceSchoolDto = new StudentAttendanceSchoolDto();
studentAttendanceSchoolDto.setAttendanceDate(date);
studentAttendanceSchoolDto.setStudentDto(studentDto);
studentAttendanceSchoolDto.setProgramSemesterDto(searchStudentAttendanceBean.getStudentAttendanceDto().getProgramSemesterDto());
studentAttendanceSchoolDto.setCreatedByAdminDto(adminDto);
return studentAttendanceSchoolDto;
}
public void onChangeAllPresent(StudentAttendanceSchoolWrapper studentAttendanceSchoolWrapper) {
for (StudentAttendanceSchoolDto studentAttendanceSchoolDto : studentAttendanceSchoolWrapper.getStudentAttendanceSchoolDtos()) {
studentAttendanceSchoolDto.setIsPresent(studentAttendanceSchoolWrapper.getTransientCheckAll());
studentAttendanceSchoolDto.setIsInformed(Boolean.FALSE);
if (!studentAttendanceSchoolWrapper.getTransientCheckAll()) {
studentAttendanceSchoolDto.setIsLate(Boolean.FALSE);
studentAttendanceSchoolDto.setReason("");
}
}
}
文件名:StudentAttendanceSchoolWrapper .java
@Getter
@Setter
public class StudentAttendanceSchoolWrapper {
private List<StudentAttendanceSchoolDto> studentAttendanceSchoolDtos;
private Boolean transientCheckAll;
public Boolean getTransientCheckAll() {
if (transientCheckAll == null) {
transientCheckAll = Boolean.FALSE;
}
return transientCheckAll;
}
}
文件名:StudentAttendanceSchoolController.java
@Getter
@Setter
@ManagedBean
@ViewScoped
public class StudentAttendanceSchoolController implements Serializable {
错误如下:
Severe: javax.faces.component.UpdateModelException: javax.el.PropertyNotFoundException: /studentDailyAttendanceSchool.xhtml @117,266 value="#{studentAttendanceSchoolWrapper.transientCheckAll}": Target Unreachable, identifier 'studentAttendanceSchoolWrapper' resolved to null
at javax.faces.component.UIInput.updateModel(UIInput.java:866)
at javax.faces.component.UIInput.processUpdates(UIInput.java:749)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1286)
at org.primefaces.component.api.UIData.process(UIData.java:457)
at org.primefaces.component.api.UIData.processFacets(UIData.java:407)
at org.primefaces.component.api.UIData.processPhase(UIData.java:390)
at org.primefaces.component.api.UIData.processUpdates(UIData.java:385)
at org.primefaces.component.api.UIData.process(UIData.java:457)
at org.primefaces.component.datatable.DataTable.processChildren(DataTable.java:1175)
at org.primefaces.component.api.UIData.processPhase(UIData.java:400)
at org.primefaces.component.api.UIData.processUpdates(UIData.java:385)
at org.primefaces.component.datatable.DataTable.processUpdates(DataTable.java:293)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1286)
at javax.faces.component.UIForm.processUpdates(UIForm.java:281)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:577)
at org.richfaces.context.MetaComponentProcessingVisitCallback.visit(MetaComponentProcessingVisitCallback.java:73)
at org.richfaces.context.BaseExtendedVisitContext.invokeVisitCallback(BaseExtendedVisitContext.java:103)
at org.richfaces.context.ExtendedExecuteVisitContext.invokeVisitCallback(ExtendedExecuteVisitContext.java:55)
at javax.faces.component.UIForm.visitTree(UIForm.java:381)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
当我勾选“检查所有”时,它可以正常工作,如下面的屏幕截图所示。当时没有错误。但是当我单击“全部保存”按钮时,它会抛出上述错误。