3 Replies Latest reply on Sep 23, 2007 7:20 PM by matt.drees

    booking example

    vlaugier

      Hello,

      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"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       xmlns:s="http://jboss.com/products/seam/taglib"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:f="http://java.sun.com/jsf"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:rich="http://richfaces.ajax4jsf.org/rich"
       xmlns:ec="http://jboss.com/products/seam/entityconverter/taglib"
       template="layout/template.xhtml">
      
      <ui:define name="body">
      
       <h:messages globalOnly="true" styleClass="message"/>
      
       <rich:panel>
       <f:facet name="header">Liste des clients</f:facet>
      
      
       <div class="input">
      
       <h:dataTable value="#{createAccount.clients}" var="potentialEditedAccount" >
       <h:column>
       <f:facet name="header">name</f:facet>
      
       #{potentialEditedAccount.id}
       </h:column>
      
       <h:column>
       <f:facet name="header">action</f:facet>
       <s:link value="Modifier le compte" action="#{createAccount.editClient(potentialEditedAccount)}"/>
       </h:column>
      
       </h:dataTable>
      
       </div>
      
       </rich:panel>
      
      </ui:define>
      
      </ui:composition>
      


      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;
      
      @Stateful
      @Name("createAccount")
      public class CreateAccountBean implements CreateAccount, Serializable {
      
       @Logger private Log log;
      
       private int value;
      
       @In FacesMessages facesMessages;
      
       @PersistenceContext(type=PersistenceContextType.EXTENDED)
       private EntityManager em;
      
       @In(required=false)
       @Out(required=false)
       private Account account ;
      
       @Out(required=false)
       @In(required=false)
       private Employee employee;
      
       @Out(required=false)
       @In(required=false)
       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";
       }
      
       @Begin
       public String createEmployee()
       {
       account = null;
       //implement your begin conversation business logic
       log.info("beginning conversation");
       return "success";
       }
      */
       public String increment()
       {
       log.info("incrementing");
       value++;
       return "success";
       }
      
       //add additional action methods that participate in this conversation
      
       @End
       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();
       client.setAccount(this.account);
       em.persist(client);
       //return "confirmClientAccount";
       }
      
       public void saveEmployee() {
       //MoralEntity moralEntity = new MoralEntity();
       //Employee employee = new Employee();
       employee.setAccount(this.account);
       em.persist(employee);
       //return "confirmEmployeeAccount";
       }
      
       @Create
       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
       */
      @Entity
      @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)
       @PrimaryKeyJoinColumn
       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


      thanks


        • 1. Re: booking example
          matt.drees

          You need to more closely imitate the booking example. The example, IIRC, uses a @DataModel to back the h:dataTable; you're using a straight List.

          • 2. Re: booking example
            vlaugier

            I had forgotten to put my datable (and so my commandbutton) in an form,

            so it was just the button that was not active ... arghh !

            thank you for your answer though

            Actually I have tried something else that does not work :

            I would like to call functions returning strings at the loading of the page so that I can have dynamic content.

            For example I would have :

            Hello #{createAccount.testing('Test1')} !! how are you today ?

            do you know by any chance a way for doing that ?

            • 3. Re: booking example
              matt.drees

              Are you using Seam 2? I think that ought to work. I'm not as sure if it would work in 1.2.