Bonjour,

j'ai voulu écrire une petite application web avec JavaEE, JSF, Hibernate et MySQL.
L'objectif est de découvrir ces outils en créant une application qui me permet de lister, rajouter, supprimer ou modifier des livres.

Cependant, j'ai une erreur lors de l'ajout d'un nouveau livre : /addBook.xhtml @10,78 value="#{beanBook.b.auteur}": Target Unreachable, 'null' returned null

« b » est l'instance du nouveau livre et « auteur » une de ses propriétés.

Voici le code de addBook :

Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                template="./template.xhtml"
                xmlns:h="http://xmlns.jcp.org/jsf/html">
 
    <ui:define name="content">
        <h2>Ajouter un nouveau livre</h2>
        <h:form>
            Auteur  : <h:inputText id="auteur" value="#{beanBook.b.auteur}"/><br/>
            Editeur :<h:inputText id="editeur" value="#{beanBook.b.editeur}"/><br/>
            Titre   :<h:inputText id="titre" value="#{beanBook.b.titre}"/><br/>
            <h:commandButton action="#{beanBook.newBook}" value="Add Book"/>
 
            <br/>
            <h:commandLink action="index" value="Retour à liste des livres"/>
        </h:form>
    </ui:define>
 
</ui:composition>
voici le beans:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.webapplicationbook.ejb;
 
import com.webapplicationbook.helper.HelperBook;
import com.webapplicationbook.pojo.Book;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import static java.util.Collections.list;
import java.util.List;
 
/**
 *
 * @author HDThoreau */
@Named(value = "beanBook")
@SessionScoped
public class BeanBook implements Serializable {
 
    HelperBook helper;
    private List<Book> list;
    private Book b;
 
    /**
     * Creates a new instance of BeanBook
     */
    public BeanBook() {
        helper = new HelperBook();
 
    }
 
    private void listOfBook(){
        list = helper.listBook();
 
    }
 
    /**
     * @return the list
     */
    public List<Book> getList() {
        listOfBook();
        return list;
    }
 
    /**
     * @param list the list to set
     */
    public void setList(List<Book> list) {
        this.list = list;
    }
 
    public Book getB() {
        return b;
    }
 
    public void setB(Book b) {
        this.b = b;
    }
 
    public void NewBook(){
        b = new Book();
        helper.addBook(b);
    }
 
 
 
}


Merci pour votre aide.
HDThoreau.