I have Course class which have a String name, and a Profesor profesor. I want to create a new Coure:
<!DOCTYPE html>
<html lang="en"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:p="http://primefaces.org/ui">
  
  <f:metadata>
    <f:event listener="#{collectionProfesor.loadProfesors()}" type="preRenderView"></f:event>
  </f:metadata> 
  
<h:head>
    <title> Create Course </title>
    <h3> Create Course </h3>
</h:head>     
  
<h:body>
    <h:form>    
        <h:panelGrid columns="3" >
            <h:outputLabel> Name</h:outputLabel>
            <h:inputText id="nameCourse" value="#{course.name}" required="true" requiredMessage="Mandatory field." />
            <h:message for="nameCourse" styleClass=""/>
            
            <h:outputLabel >Profesor </h:outputLabel>
            <h:selectOneMenu  value="#{course.profesor}" layout="grid" columns="2">
                 <f:selectItems  var="profesorAux" value="#{collectionProfesor.profesors}" />
            </h:selectOneMenu>
                        
            <h:outputLabel/>        
            <h:commandButton value="Submit" action="#{collectionCourse.addCourse(course)}" />   
        </h:panelGrid>
    </h:form> 
    
    <h:outputLink value="Course.xhtml">Back to Course List</h:outputLink>   
</h:body>       
In CollectionProfesor, I have a List with professor, and that list is populate with this method collectionProfesor.loadProfesors();
h:selectOneMenu value="#{course.profesor}" layout="grid" columns="2" --- Here, I want to make course.setProfesor()
f:selectItems var="profesorAux" value="#{collectionProfesor.profesors}" ---collectionProfesor.profesors return the list with profesors which is created here ---f:event listener="#{collectionProfesor.loadProfesors()}" type="preRenderView"
h:commandButton value="Submit" action="#{collectionCourse.addCourse(course)}" --collecionCourse class has a list of coursses. The addCourse(Course course), add the course to the list
But I receive an error (null pointer exception).The page is render, and all the professor appear, but when I click submit I have an error. Can you help me?