0

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?

Community
  • 1
  • 1
  • Can you post the error/stack trace you are getting? – Michael Markidis May 20 '16 at 07:04
  • No, we can't help you. Just read your question again; and consider what somebody would need in order to be able to help you. Hint: maybe some more information about the nature of that failure? – GhostCat May 20 '16 at 07:13
  • Ok. I will make a question more detalied – Florin Moldovan May 20 '16 at 07:19
  • I will get the error trace in 5,6 hours (I don't have the project here) – Florin Moldovan May 20 '16 at 07:47
  • Your question boils down to "Why do I get a NullPointerException?". The duplicate answers exactly that. Once you're capable of asking "Why is variable X null?" while pointing out the exact variable X in a MCVE code snippet, and you still can't figure out the root cause, then feel free to ask a new question. At least, exceptions of java.lang.* package originating in your own code are basic Java problems not JSF/JavaEE related problems. – BalusC May 20 '16 at 09:14
  • BalusC, I will make a new question. Hope you can help me – Florin Moldovan May 20 '16 at 09:25

0 Answers0