0

Hello I want to show the add form page. when i click on button it throw that error. I am also using the @Named annotations because @ManagedBean annotations is deprecated. So Help me to solve out this error.

ProfessorController.java:

package databank.jsf;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;


import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import databank.dao.ListDataDao;
import databank.dao.ProfessorDao;
import databank.model.ProfessorPojo;

@Named("professorController")
@RequestScoped
public class ProfessorController implements Serializable {
    private static final long serialVersionUID = 1L;

    @Inject
    private Map<String, Object> sessionMap;

    @Inject
    private ProfessorDao professorDao;

    @Inject
    private ListDataDao listDataDao;

    private List<ProfessorPojo> professors;

    public void loadProfessors() {
        setProfessors(professorDao.readAllProfessors());
    }

    public List<ProfessorPojo> getProfessors() {
        return professors;
    }

    public void setProfessors(List<ProfessorPojo> professors) {
        this.professors = professors;
    }

    public List<String> getDegrees() {
        return listDataDao.readAllDegrees();
    }

    public List<String> getMajors() {
        return listDataDao.readAllMajors();
    }

    public String navigateToAddForm() {
        sessionMap.put("newProfessor", new ProfessorPojo());
        return "add-professor.xhtml?faces-redirect=true";
    }

    public String submitProfessor(ProfessorPojo professor) {
        professor.setCreated(LocalDateTime.now());
        professorDao.createProfessor(professor);
        return "list-professors.xhtml?faces-redirect=true";
    }

    public String navigateToUpdateForm(int professorId) {
        ProfessorPojo professor = professorDao.readProfessorById(professorId);
        sessionMap.put("editProfessor", professor);
        return "edit-professor.xhtml?faces-redirect=true";
    }

    public String submitUpdatedProfessor(ProfessorPojo professor) {
        professorDao.updateProfessor(professor);
        return "list-professors.xhtml?faces-redirect=true";
    }

    public String deleteProfessor(int professorId) {
        professorDao.deleteProfessorById(professorId);
        return "list-professors.xhtml?faces-redirect=true";
    }

    public String editProfessor(int professorId) {
        ProfessorPojo professor = professorDao.readProfessorById(professorId);
        sessionMap.put("professorToEdit", professor);
        return "edit-professors.xhtml?faces-redirect=true";
    }
}

face-config.xml:

`<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                                  http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd"
              version="2.3">
 
    
    <application>
    <resource-bundle>
      <base-name>Bundle</base-name>
      <var>uiconsts</var>
    </resource-bundle>
  </application>
</faces-config>`

list-professors.xhtml:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html>
<html
  lang="en"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:jsf="http://xmlns.jcp.org/jsf"
  xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
  xmlns:f="http://xmlns.jcp.org/jsf/core"
  xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
  >
  <!-- Professor CRUD View -->

  <h:head>
    <!-- Title of tab/window in browser -->
    <title>#{uiconsts['viewTitle']}</title>
    <!-- Modern front-end artifacts such as CSS, JavaScript, etc. -->
    <!-- Misc. table styles -->
    <style>
        table {
          border: solid 1px #DDEEEE;
          border-collapse: collapse;
          border-spacing: 0;
          table-layout: auto;
          width: 95%;
        }
        table td {
          border: solid 1px #DDEEEE;
        }
        table th {
          border: solid 1px black;
          background-color: #d8d8d8;
        }
        table tr:nth-child(even) {
          background: #f2f2f2;
        }
        .table-hover tbody tr:hover td, .table-hover tbody tr:hover th {
          background-color: #f0f0e0;
        }
        caption {
          white-space: nowrap;
          caption-side: bottom;
        }
    </style>
  </h:head>
  <h:body>
    <h2>#{uiconsts['viewTitle']}</h2>
    <br />
    <h:form>
       <!-- JavaScript onclick-handler cannot use 'map-style' uiconsts['something'], use 'properties-style'  -->
       <h:commandButton value="#{uiconsts['addButtonLabel']}" action="#{professorController.navigateToAddForm()}" />
       <p/>
       <h:dataTable value="#{professorController.professors}"  action="#{professorController.loadProfessors()}" var="prof"
         styleClass="table table-hover">
         <h:column>
           <f:facet name="header">#{uiconsts['columnLabel_Id']}</f:facet>
           <h:outputText value="#{prof.id}"/>
         </h:column>
         <h:column>
             <f:facet name="header">#{uiconsts['columnLabel_LastName']}</f:facet>
             <h:outputText value="#{prof.lastName}"/>
         </h:column>
         <h:column>
             <f:facet name="header">#{uiconsts['columnLabel_FirstName']}</f:facet>
             <h:outputText value="#{prof.firstName}"/>
         </h:column>
         <h:column>
             <f:facet name="header">#{uiconsts['columnLabel_Email']}</f:facet>
             <h:outputText value="#{prof.email}"/>
         </h:column>
         <h:column>
             <f:facet name="header">#{uiconsts['columnLabel_PhoneNumber']}</f:facet>
             <h:outputText value="#{prof.phoneNumber}"/>
         </h:column>
         <h:column>
             <f:facet name="header">#{uiconsts['columnLabel_Degree']}</f:facet>
             <h:outputText value="#{prof.degree}"/>
         </h:column>
         <h:column>
             <f:facet name="header">#{uiconsts['columnLabel_Major']}</f:facet>
             <h:outputText value="#{prof.major}"/>
         </h:column>
         <h:column>
             <f:facet name="header">#{uiconsts['columnLabel_Created']}</f:facet>
             <h:outputText value="#{prof.created}"/>
         </h:column>
         <!-- 
         Action column 
         you can add an action instead of onclick to edit button
         -->
         <h:column>
           <f:facet name="header">#{uiconsts['columnLabel_Action']}</f:facet>
           <h:commandButton value="#{uiconsts['editButtonLabel']}" 
           onclick ="if (!confirm('#{uiconsts.rus}')) return false"
             action="#{professorController.navigateToUpdateForm(prof.id)}" />
           &#160;
           <h:commandButton value="#{uiconsts['deleteButtonLabel']}"
             onclick="if (!confirm('#{uiconsts.rus}')) return false"
             action="#{professorController.deleteProfessor(prof.id)}" />
         </h:column>
         <f:facet name="caption">#{uiconsts['listCaption']} - Created by:  #{uiconsts['footer.studentname']} #{uiconsts['footer.studentnumber']} #{uiconsts['footer.labsection']}</f:facet>
       </h:dataTable>
    </h:form>
  </h:body>
</html>

I am also using the beans.xml file.

I am try to find the solution but not get a suitable solution. I am using Payara6 server for running this website.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
  • 1
    Why are you using JSF 2.2 with Payara 6? Payara 6 is a Jakarta EE 10 server (bundled with JSF 4). – Jasper de Vries Jun 01 '23 at 07:55
  • Does this answer your question? [Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable](https://stackoverflow.com/questions/30128395/identifying-and-solving-javax-el-propertynotfoundexception-target-unreachable) – Jasper de Vries Jun 01 '23 at 07:56
  • i am using jsf 2.2 -Jasper de Vries – Rashid Ashfaq Jun 01 '23 at 10:25
  • This is genuinely confusing. Payara 6 provides Faces 4.0. Your faces-config.xml says JSF 2.3. You think that you're using JSF 2.2. What is this? If you want to use JSF 2.2 then you should be using Payara 4. If you want to use JSF 2.3 then you should be using Payara 5. If you want to use Faces 4.0 then you should be using Payara 6. No need to manually put JARs into WEB-INF/lib of WAR. Payara is a normal JEE server not a servletcontainer like Tomcat. – BalusC Jun 01 '23 at 11:36
  • This is perhaps the real answer to your question: https://stackoverflow.com/questions/8081234/how-to-properly-install-and-configure-jsf-libraries-via-maven – BalusC Jun 01 '23 at 11:38

0 Answers0