1 Reply Latest reply on Oct 12, 2007 8:28 AM by pmuir

    Creating components

    cfthomas

      Hi there!

      I'm new to SEAM so maybe you can give me some hints:

      I want to create a generic component (not a component as in SEAM but a component as in "reusable building block")

      I have a nice JavaScript Table that features all nice things you can imagine. It's written completely in Javascript and support event-handlers.
      So What you need to do is write your JavaScript code to setup the table and add event-handler that then call e.g. SEAM components via remoting.
      That works fine but for my likings is too much reapeated code every time you want to display some tables.

      I want to create a SEAM component that encapsulates the initial creation of the table and handles all the events (sorting, paging, ..).
      The only thing you need to do is just configure it what entity/datasource it should use.

      E.g.:

      @Stateful
      public TableBean extends Table
      {
       int currentPage; // Remembers the current page
       String sortedColumn; // The name of column that is currently sorted or null
       String entityName; // Name of the entity to use (componentName or className)
       List<String> propertyNames; // Names of properties to display
       List<String> columnTitles; // Column Titles for the displayed columns
      
       // Returns the JavaScript neccessary to setup the table in the browser
       String create() {}
      
       // Returns a list of queried data
       List getData() {}
      
       // Sets the current page
       void pageTo(int newPage);
      
       // Sets the sortedColumn
       void sort(String column);
      
       void select(Integer id);
      }
      

      The idea behind is to somehow (is this even possible in SEAM?) create multisple instances and configure them:
      <component name="customerTable">
       <type class="TableBean"/>
       <property name="entityName">acme.Customer</property>
       <property name="propertyNames">
       <list>
       <value>name</value>
       <value>email</value>
       </list>
       </property>
       <property name="columnTitles">
       <list>
       <value>Cust. Name</value>
       <value>Email-Address</value>
       </list>
       </property>
      </component>
      

      in that way I want to configure say an "articleTable", "companyTable" etc. etc. without writing any new java or javascript code.

      please help me with that:

      * How can I configure multiple "instances" of the same component/ejb

      * Can conversations help me manage the state of such a component (currentPage, sortedColumn ..)


      Thank you very much!

      Thomas


        • 1. Re: Creating components
          pmuir

          You're almost there

          <component name="customerTable" class="my.TableBean">
           <property name="entityName">acme.Customer</property>
           <property name="propertyNames">
           <value>name</value>
           <value>email</value>
           </property>
           <property name="columnTitles">
           <value>Cust. Name</value>
           <value>Email-Address</value>
           </property>
          </component>


          and just create many of these in your components.xml keeping the class the same.