3 Replies Latest reply on Sep 23, 2007 7:20 PM by Matt Drees

    booking example

    Vincent LAUGIER Newbie


      I have a form that gives me a list of accounts, in the same way that main.xhtml presents a list of hotels in the booking example.

      I want to pass an account instance as an argument to a function (this function will assign the instance as the current account to be edited and redirect to the editoin form), in the same way that we have in the booking example :

      <s:link value="View Hotel" action="#{hotelBooking.selectHotel(hot)}"/>

      but in my case I get a java null pointer exception.

      Here is my form
      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
      <ui:define name="body">
       <h:messages globalOnly="true" styleClass="message"/>
       <f:facet name="header">Liste des clients</f:facet>
       <div class="input">
       <h:dataTable value="#{createAccount.clients}" var="potentialEditedAccount" >
       <f:facet name="header">name</f:facet>
       <f:facet name="header">action</f:facet>
       <s:link value="Modifier le compte" action="#{createAccount.editClient(potentialEditedAccount)}"/>

      here is my manager bean
      package fr.helmet.portal.manager;
      import fr.helmet.portal.entity.Account;
      import fr.helmet.portal.entity.Client;
      import fr.helmet.portal.entity.Employee;
      import java.io.Serializable;
      import java.util.List;
      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      import javax.persistence.PersistenceContextType;
      import org.jboss.seam.annotations.Create;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.End;
      import org.jboss.seam.annotations.Destroy;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.core.FacesMessages;
      import org.jboss.seam.log.Log;
      public class CreateAccountBean implements CreateAccount, Serializable {
       @Logger private Log log;
       private int value;
       @In FacesMessages facesMessages;
       private EntityManager em;
       private Account account ;
       private Employee employee;
       private Client client;
       private List<Employee> employees;
       private List<Client> clients;
      /** @Begin
       public String createClient()
       //account = null;
       //implement your begin conversation business logic
       log.info("beginning conversation");
       return "createAccountClient";
       public String createEmployee()
       account = null;
       //implement your begin conversation business logic
       log.info("beginning conversation");
       return "success";
       public String increment()
       return "success";
       //add additional action methods that participate in this conversation
       public String end()
       //implement your end conversation business logic
       log.info("ending conversation");
       return "home";
       public int getValue()
       return value;
       @Destroy @Remove
       public void destroy() {}
       public Account getAccount() {
       return account;
       public void setAccount(Account account) {
       this.account = account;
       public void saveClient() {
       Client client = new Client();
       //return "confirmClientAccount";
       public void saveEmployee() {
       //MoralEntity moralEntity = new MoralEntity();
       //Employee employee = new Employee();
       //return "confirmEmployeeAccount";
       public void find() {
       this.employees = em.createQuery("select e from Employee e").getResultList();
       this.clients = em.createQuery("select c from Client c").getResultList();
       public List<Employee> getEmployees() {
       return employees;
       public void setEmployees(List<Employee> employees) {
       this.employees = employees;
       public List<Client> getClients() {
       return clients;
       public void setClients(List<Client> clients) {
       this.clients = clients;
       public Employee getEmployee() {
       return employee;
       public void setEmployee(Employee employee) {
       this.employee = employee;
       public String editClient(Client clt) {
       this.client = clt;
       System.out.println("ID du client = " + this.client.getId()) ;
       //System.out.println("editAccount " + this.client.getAccount().getFullname());
       //facesMessages.add("editAccount " + this.client.getAccount().getFullname());
       //this.account = client.getAccount();
       return "createAccount";
       public Client getClient() {
       return client;
       public void setClient(Client client) {
       this.client = client;

      here is my entity bean
      package fr.helmet.portal.entity;
      // Generated 16 sept. 2007 18:19:54 by Hibernate Tools 3.2.0.b9
      import java.util.HashSet;
      import java.util.Set;
      import javax.persistence.CascadeType;
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.ManyToOne;
      import javax.persistence.OneToOne;
      import javax.persistence.OneToMany;
      import javax.persistence.PrimaryKeyJoinColumn;
      import javax.persistence.Table;
      import org.hibernate.validator.Length;
      import org.hibernate.validator.NotNull;
       * Client generated by hbm2java
      @Table(name = "CLIENT")
      public class Client implements java.io.Serializable {
       private int id ;
       private Account account;
       private Set<ServiceOrder> serviceOrders = new HashSet<ServiceOrder>(0);
       public Client() {
       public Client(String fullname,
       String email,
       String phone,
       String mobile,
       String fax,
       String address,
       String postcode,
       String city) {
       this.account = new Account(fullname,email,phone,mobile,
       fax, address, postcode, city) ;
       @Id @GeneratedValue
       public int getId() {
       return id;
       public void setId(int id) {
       this.id = id ;
       @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
       public Account getAccount() {
       return this.account;
       public void setAccount(Account account) {
       this.account = account;
       @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "client")
       public Set<ServiceOrder> getServiceOrders() {
       return this.serviceOrders;
       public void setServiceOrders(Set<ServiceOrder> serviceOrders) {
       this.serviceOrders = serviceOrders;

      if you have any idea, this will allow me not to use the pid as argument and keep the code elegant