javax.faces.component.UpdateModelException: javax.el.PropertyNotFoundException. Target Unreachable, identifier resolved to null
Asked Answered
D

0

0

Solution of this question already exists in stackoverflow. Although I have asked this question, it is because all available answers doesn't solve my problem/error. So I have asked this question so that I can explain my scenario on which I am getting this bug.

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

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

Filename : 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;
}
}

Filename : StudentAttendanceSchoolController.java

@Getter
@Setter
@ManagedBean
@ViewScoped
public class StudentAttendanceSchoolController implements Serializable {

Error is as follows :

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)

When I tick 'Check All' it works fine as shown in below screenshot. There is no error at that time. But When I click 'Save All' button it throws above error.

When I tick 'Check All' it works fine as shown in below screenshot. There is no error at that time. But When I click 'Save All' button it throws above error.

Draught answered 2/11, 2021 at 13:5 Comment(4)
@BalusC studentAttendanceSchoolWrapper can never be null as I have added new objects only after creating it in list studentAttendanceSchoolWrappers. so don't know why it is throwing 'Target Unreachable'. If you once look at my code you can understand the scenario .Draught
@BalusC the managed bean contains list of studentAttendanceSchoolWrapper i.e. studentAttendanceSchoolWrappers. So the managed bean don't have getter of studentAttendanceSchoolWrapper. I am using p:columns inside p:datatable.Draught
@BalusC managed bean is actually a javax.faces.bean.ViewScoped bean.Draught
@BalusC Yes it obviously contains getter of studentAttendanceSchoolWrappers(list). I was saying the managed bean does't have getter of studentAttendanceSchoolWrapper(an object).Draught

© 2022 - 2024 — McMap. All rights reserved.