3 Replies Latest reply on Feb 25, 2010 1:13 PM by vitorsouzabr

    Property annotated with @DataModel on superclass across different pages

    vitorsouzabr

      Hello,


      I have developed a generic abstract class for CRUD controllers. It contains some generic code and when I need to develop a CRUD, I create a specific on, like:


      @AutoCreate
      @Name("manageProductsAction")
      @Scope(ScopeType.SESSION)
      public class ManageProductsAction extends CrudAction<Product, Long> {
      



      The CRUD is a master-detail divided in two pages: listing and form. On the listing, I show some properties of the existing objects.


      Now for class Product I show only the name, while for the class Client I have a CRUD that shows name and email of the clients. But a strange error is occurring. Here are the steps to reproducing it (happens every time):


      1 - Click on http://localhost:8080/mysystem/mypackageB/manageProducts/list.seam link to open listing of products;


      2 - Click on http://localhost:8080/mysystem/mypackageA/manageClients/list.seam link to open listing of clients;


      3 - Exception is thrown:


      javax.el.PropertyNotFoundException: /mypackageA/manageClients/list.xhtml @65,47 value="#{entity.email}": Property 'email' not found on type mypackageB.domain.Product
      



      Both ManageProductsAction and ManageClientsAction extend CrudAction. The superclass defines a data model:


      @DataModel
      protected List<T> entities;
      



      In both list.xhtml pages (clients and products), this data model is accessed by a <h:dataTable value="#{entities}" var="entity" /> tag. Furthermore, if I open the products listing, open the main home page again and then go to the clients listing, everything works fine. No exception.


      I don't know why the #{entities} data model is filled with Product objects when I open the clients page from the products page. I thought that maybe the #{entities} that was outjected by the products listing wasn't replaced by the one that the clients listing is supposed to outject. So when the clients listing is redenred, #{entities} is filled with Product instances, which don't have an email property, thus the exception.


      Can this happen? If so, what have I done wrong to allow it? How do I fix it?


      Both list.xhtml pages have an accompanying list.page.xml file like this (... used to suppress irrelevant code):


      <?xml version="1.0" encoding="UTF-8"?>
      <page ... login-required="true">
        <begin-conversation join="true" flush-mode="MANUAL" />
        <action execute="#{manageClientsAction.list}" />
      </page>
      



      The list() method referred to by the XML file loads the objects from the database and places them in the entities property.


      Please help and let me know if you need any further information.


      Thanks a lot,


      Vítor Souza