problem when I want to persist data
yohann49 Jul 30, 2007 4:02 AMHi !!
I want to persist data in my database. However I have an error :
Exception during request processing: javax.servlet.ServletException: /abonnement_contact.xhtml @17,68 value="#{contact.firstName}": Target Unreachable, identifier 'contact' resolved to null
Here is my ContactManager :
@Stateful
@Name("ContactManager")
@Scope(SESSION)
public class ContactManager implements com.pingwy.web.front.ContactManagerLocal, Serializable{
@In
private EntityManager em;
@In (create = true, required = true) @Out
private Contact contact;
@In @Out (required = false)
Contact currentContact;
public String updateContact(){
em.merge(currentContact);
return null;
}
public String removeContact (){
System.out.println("contact bientot supprimé");
em.remove(currentContact);
return null;
}
public String createContact(Contact c){
contact = c;
em.persist(contact);
return null;
}
@Remove @Destroy
public void destroy(){
}
public Contact getContact() {
return contact;
}
public void setContact(Contact contact) {
this.contact = contact;
}
}
and my page :
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<body>
<ui:composition template="templates/client.xhtml">
<ui:define name="servicesclients">
<h:form>
<h3>Contact</h3>
<h:panelGrid columns="2">
<h:outputLabel value="FirstName :"/>
<h:inputText value="#{contact.firstName}"/>
<h:outputLabel value="LastName :"/>
<h:inputText value="#{contact.lastName}"/>
<h:outputLabel value="Phone :"/>
<h:inputText value="#{contact.phone}"/>
<h:outputLabel value="Other Phone :"/>
<h:inputText value="#{contact.otherPhone}"/>
<h:outputLabel value="Mail :"/>
<h:inputText value="#{contact.mail}"/>
<h:outputLabel value="Username :"/>
<h:inputText value="#{contact.username}"/>
<h:outputLabel value="Password :"/>
<h:inputText value="#{contact.password}"/>
<h:outputLabel value="Fax :"/>
<h:inputText value="#{contact.fax}"/>
<h:outputLabel value="Position :"/>
<h:inputText value="#{contact.position}"/>
</h:panelGrid>
<h:commandButton id="change" value="Change" action="#{ContactManager.createContact(contact)}"/>
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
thanks in advance