J2ee/javaee
booloo
Messages postés
100
Statut
Membre
-
booloo Messages postés 100 Statut Membre -
booloo Messages postés 100 Statut Membre -
Bonjour,
j'ai crée une application web jsf, mais en lançant la compilation, voici ce qui s'affiche sur mon navigateur:
javax.servlet.ServletException: The class 'com.ensode.jsf.managedbeans.RegistrationBean' does not have the property 'firstname'
pourtant j'ai bien defini firstname:
private String firstName;
getters et setters
S'il vous plait toute aide me sera precieuse.
j'ai crée une application web jsf, mais en lançant la compilation, voici ce qui s'affiche sur mon navigateur:
javax.servlet.ServletException: The class 'com.ensode.jsf.managedbeans.RegistrationBean' does not have the property 'firstname'
pourtant j'ai bien defini firstname:
private String firstName;
getters et setters
S'il vous plait toute aide me sera precieuse.
A voir également:
- J2ee/javaee
- Eclipse j2ee - Télécharger - Langages
- La =\= entre J2SE, J2EE et J2ME - Forum Programmation
- J2EE : EJB vs JavaBean ? Quelles différences ? ✓ - Forum Java
4 réponses
Bonsoir Booloo,
Désolé, le compilateur a raison : tu n'as pas respecté la casse :
Ton attribut est : private String firstName;
et ton RegstrationBean devrait être (je crois) firstName
Remarque importante (et là, j'en suis sûr) :
Ton getter DOIT ETRE : getFirstName
Ton setter DOIT ETRE : setFirstName
Désolé, le compilateur a raison : tu n'as pas respecté la casse :
Ton attribut est : private String firstName;
et ton RegstrationBean devrait être (je crois) firstName
Remarque importante (et là, j'en suis sûr) :
Ton getter DOIT ETRE : getFirstName
Ton setter DOIT ETRE : setFirstName
Salut, regarde mon code de RegistrationBean
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.ensode.jsf.managedbeans;
/**
*
* @author Od
*/
public class RegistrationBean {
/** Creates a new instance of RegistrationBean */
public RegistrationBean() {
}
private String salutation;
private String firstName;
private String lastName;
private Integer age;
private String email;
public Integer getAge() {
return age;
}
public String getEmail() {
return email;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getSalutation() {
return salutation;
}
public void setAge(Integer age) {
this.age = age;
}
public void setEmail(String email) {
this.email = email;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setSalutation(String salutation) {
this.salutation = salutation;
}
La meme erreur persiste.
Merci.
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.ensode.jsf.managedbeans;
/**
*
* @author Od
*/
public class RegistrationBean {
/** Creates a new instance of RegistrationBean */
public RegistrationBean() {
}
private String salutation;
private String firstName;
private String lastName;
private Integer age;
private String email;
public Integer getAge() {
return age;
}
public String getEmail() {
return email;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getSalutation() {
return salutation;
}
public void setAge(Integer age) {
this.age = age;
}
public void setEmail(String email) {
this.email = email;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setSalutation(String salutation) {
this.salutation = salutation;
}
La meme erreur persiste.
Merci.
}
Bonjour,
Et peux-tu envoyer aussi le code qui appelle cette registrationBean car le problème serait une non concordance entre la définition de la classe et son appel.
Concernant la définition de la classe, je ne vois pas de problème , en effet.
Et peux-tu envoyer aussi le code qui appelle cette registrationBean car le problème serait une non concordance entre la définition de la classe et son appel.
Concernant la définition de la classe, je ne vois pas de problème , en effet.
Bonsoir BadGuistarist, voici ce code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.book;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
/**
*
* @author Od
*/
@Entity
@NamedQuery(name="findAllBooks", query="SELECT b FROM Book b")
public class Book implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable=false)
private String title;
private Float price;
@Column(length=2000)
private String description;
private String isbn;
private Integer nbOfPage;
private Boolean illustration;
public Book(Long id, String title, Float price, String description, String isbn, Integer nbOfPage, Boolean illustration) {
this.id = id;
this.title = title;
this.price = price;
this.description = description;
this.isbn = isbn;
this.nbOfPage = nbOfPage;
this.illustration = illustration;
}
public String getDescription() {
return description;
}
public Boolean getIllustration() {
return illustration;
}
public String getIsbn() {
return isbn;
}
public Integer getNbOfPage() {
return nbOfPage;
}
public Float getPrice() {
return price;
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public String getTitle() {
return title;
}
public void setDescription(String description) {
this.description = description;
}
public void setIllustration(Boolean illustration) {
this.illustration = illustration;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public void setNbOfPage(Integer nbOfPage) {
this.nbOfPage = nbOfPage;
}
public void setPrice(Float price) {
this.price = price;
}
public void setTitle(String title) {
this.title = title;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Book)) {
return false;
}
Book other = (Book) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "org.book.Book[id=" + id + "]";
}
}
Voici les deux session Beans qui doivent traiter l'entity precedent:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.session;
import javax.ejb.Local;
/**
*
* @author Od
*/
@Local
public interface BookEJBLocal {
public java.util.List<java.awt.print.Book> findBooks();
public java.awt.print.Book createBook(java.awt.print.Book book);
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.session;
import java.awt.print.Book;
import java.util.List;
import javax.ejb.Stateless;
import javax.management.Query;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
/**
*
* @author Od
*/
@Stateless
public class BookEJBBean implements BookEJBLocal {
@PersistenceContext(unitName="Book-ejbPU")
private EntityManager em;
public List<Book> findBooks(){
Query query=(Query) em.createNamedQuery("findAllBooks");
return query.getResultList();
}
public Book createBook(Book book){
em.persist(book);
return book;
}
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method" or "Web Service > Add Operation")
}
Le probleme est que , la ligne: return query.getResultList();
Affiche une erreur
Aider moi s'il vous plait.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.book;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
/**
*
* @author Od
*/
@Entity
@NamedQuery(name="findAllBooks", query="SELECT b FROM Book b")
public class Book implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable=false)
private String title;
private Float price;
@Column(length=2000)
private String description;
private String isbn;
private Integer nbOfPage;
private Boolean illustration;
public Book(Long id, String title, Float price, String description, String isbn, Integer nbOfPage, Boolean illustration) {
this.id = id;
this.title = title;
this.price = price;
this.description = description;
this.isbn = isbn;
this.nbOfPage = nbOfPage;
this.illustration = illustration;
}
public String getDescription() {
return description;
}
public Boolean getIllustration() {
return illustration;
}
public String getIsbn() {
return isbn;
}
public Integer getNbOfPage() {
return nbOfPage;
}
public Float getPrice() {
return price;
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public String getTitle() {
return title;
}
public void setDescription(String description) {
this.description = description;
}
public void setIllustration(Boolean illustration) {
this.illustration = illustration;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public void setNbOfPage(Integer nbOfPage) {
this.nbOfPage = nbOfPage;
}
public void setPrice(Float price) {
this.price = price;
}
public void setTitle(String title) {
this.title = title;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Book)) {
return false;
}
Book other = (Book) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "org.book.Book[id=" + id + "]";
}
}
Voici les deux session Beans qui doivent traiter l'entity precedent:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.session;
import javax.ejb.Local;
/**
*
* @author Od
*/
@Local
public interface BookEJBLocal {
public java.util.List<java.awt.print.Book> findBooks();
public java.awt.print.Book createBook(java.awt.print.Book book);
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.session;
import java.awt.print.Book;
import java.util.List;
import javax.ejb.Stateless;
import javax.management.Query;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
/**
*
* @author Od
*/
@Stateless
public class BookEJBBean implements BookEJBLocal {
@PersistenceContext(unitName="Book-ejbPU")
private EntityManager em;
public List<Book> findBooks(){
Query query=(Query) em.createNamedQuery("findAllBooks");
return query.getResultList();
}
public Book createBook(Book book){
em.persist(book);
return book;
}
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method" or "Web Service > Add Operation")
}
Le probleme est que , la ligne: return query.getResultList();
Affiche une erreur
Aider moi s'il vous plait.