2 Replies Latest reply on Feb 23, 2010 3:44 PM by Tristan Dyer

    Any Seam example using RichFace binding attribute?

    I need a real name Newbie

      Hello,


      I have this issue for many days. Most of codes are from Richfaces demo. But I need to combine Seam and Richface. It seems that I have to use binding attribute. But I always got error message. I wonder if anyone can help me out? Thanks.


      I got below error message:
      javax.el.ELException: /conversation.xhtml @22,64 binding="#{dataTableScrollerBean.table}": java.lang.IllegalArgumentException: argument type mismatch


      Here is my code:


      RichFaces codes



      <rich:scrollableDataTable rowKeyVar="rkv" frozenColCount="1" height="400px" 
                      width="700px" id="carList" rows="40" columnClasses="col"
                      value="#{dataTableScrollerBean.allCars}" var="category" sortMode="single"
                      binding="#{dataTableScrollerBean.table}"
                      sortOrder="#{dataTableScrollerBean.order}"
                      selection="#{dataTableScrollerBean.selection}">
      
                                      <rich:column id="make">
                                              <f:facet name="header"><h:outputText styleClass="headerText" value="Make" /></f:facet>
                                              <h:outputText value="#{category.make}" />
                                      </rich:column>
                                      <rich:column id="model">
                                              <f:facet name="header"><h:outputText styleClass="headerText" value="Model" /></f:facet>
                                              <h:outputText value="#{category.model}" />
                                      </rich:column>
                                      <rich:column id="price">
                                              <f:facet name="header"><h:outputText styleClass="headerText" value="Price" /></f:facet>
                                              <h:outputText value="#{category.price}" />
                                      </rich:column>
                                      <rich:column id="mileage">
                                              <f:facet name="header"><h:outputText styleClass="headerText" value="Mileage" /></f:facet>
                                              <h:outputText value="#{category.mileage}" />
                                      </rich:column>
                                      <rich:column width="200px" id="vin">
                                              <f:facet name="header"><h:outputText styleClass="headerText" value="VIN" /></f:facet>
                                              <h:outputText value="#{category.vin}" />
                                      </rich:column>
                                      <rich:column id="stock">
                                              <f:facet name="header"><h:outputText styleClass="headerText" value="Stock" /></f:facet>
                                              <h:outputText value="#{category.stock}" />
                                      </rich:column>
                              </rich:scrollableDataTable>
      
      





      Java codes



      /**
       * 
       */
      package com.cgi.kym.action;
      
      import java.math.BigDecimal;
      import java.util.ArrayList;
      import java.util.Arrays;
      import java.util.HashSet;
      import java.util.Iterator;
      import java.util.List;
      import java.util.Random;
      import java.util.Set;
      
      import javax.ejb.Stateful;
      import javax.ejb.Stateless;
      import javax.faces.context.FacesContext;
      import javax.faces.event.ActionEvent;
      import javax.faces.model.SelectItem;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Factory;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.richfaces.component.UIScrollableDataTable;
      import org.richfaces.component.html.HtmlScrollableDataTable;
      import org.richfaces.model.SortField;
      import org.richfaces.model.SortOrder;
      import org.richfaces.model.selection.SimpleSelection;
      
      /**
       * @author Nick Belaevski - nbelaevski@exadel.com created 02.03.2007
       * 
       */
      
      @Name("dataTableScrollerBean")
      @Scope(ScopeType.SESSION)
      
      public class DataTableScrollerBean implements java.io.Serializable {
      
              private DemoInventoryItem currentItem = new DemoInventoryItem();
      
              private int rows = 10;
      
              /* (non-Javadoc)
               * @see com.cgi.kym.action.IDataTableScroller#getRows()
               */
              public int getRows() {
                      return rows;
              }
      
              /* (non-Javadoc)
               * @see com.cgi.kym.action.IDataTableScroller#setRows(int)
               */
              public void setRows(int rows) {
                      this.rows = rows;
              }
      
              /* (non-Javadoc)
               * @see com.cgi.kym.action.IDataTableScroller#fetchCurrentRow(javax.faces.event.ActionEvent)
               */
              public void fetchCurrentRow(ActionEvent event) {
                      String vin=(FacesContext.getCurrentInstance().
                                      getExternalContext().getRequestParameterMap().get("vin"));
                      currentRow = Integer.parseInt(FacesContext.getCurrentInstance().
                                      getExternalContext().getRequestParameterMap().get("row"));
                      for (DemoInventoryItem item : allCars) {
                              if (item.getVin().equals(vin)){
                                      currentItem=item;
                                      break;
                              }
                      }
              }
      
              private Set<Integer> keys = new HashSet<Integer>();
      
              private int currentRow;
      
              //@In (required=false) @Out(required=false) 
              private static SimpleSelection selection = new SimpleSelection();
      
              private UIScrollableDataTable table;
      
              private SortOrder order = new SortOrder();
      
              private int scrollerPage=1;
      
              private ArrayList<DemoInventoryItem[]> model = null;
      
              private ArrayList<DemoInventoryItem> selectedCars = new ArrayList<DemoInventoryItem>();
              private ArrayList<Facet> columns = new ArrayList<Facet>();
              private static int DECIMALS = 1;
              private static int ROUNDING_MODE = BigDecimal.ROUND_HALF_UP;
              //@DataModel
              private List<DemoInventoryItem> allCars = null;
          
              
              public DataTableScrollerBean() {
                      initColumnsHeaders();
                      SortField[] fields = { new SortField("make", true) };
                      order.setFields(fields);
              }
      
              
              public List<DemoInventoryItem> getAllCars() {
                      synchronized (this) {
                              if (allCars == null) {
                                      allCars = new ArrayList<DemoInventoryItem>();
                                      for (int k = 0; k <= 5; k++) {
                                              try {
                                                      switch (k) {
                                                      case 0:
                                                              allCars
                                                                              .addAll(createCar("Chevrolet", "Corvette",
                                                                                              5));
                                                              allCars.addAll(createCar("Chevrolet", "Malibu", 8));
                                                              allCars.addAll(createCar("Chevrolet", "S-10", 10));
                                                              allCars.addAll(createCar("Chevrolet", "Tahoe", 6));
                                                              break;
      
                                                      case 1:
                                                              allCars.addAll(createCar("Ford", "Taurus", 12));
                                                              allCars.addAll(createCar("Ford", "Explorer", 11));
                                                              break;
                                                      case 2:
                                                              allCars.addAll(createCar("Nissan", "Maxima", 9));
                                                              break;
                                                      case 3:
                                                              allCars.addAll(createCar("Toyota", "4-Runner", 7));
                                                              allCars.addAll(createCar("Toyota", "Camry", 15));
                                                              allCars.addAll(createCar("Toyota", "Avalon", 13));
                                                              break;
                                                      case 4:
                                                              allCars.addAll(createCar("GMC", "Sierra", 8));
                                                              allCars.addAll(createCar("GMC", "Yukon", 10));
                                                              break;
                                                      case 5:
                                                              allCars.addAll(createCar("Infiniti", "G35", 6));
                                                              break;
                                                      /*
                                                       * case 6: allCars.addAll(createCar("UAZ","469", 6));
                                                       * break;
                                                       */
                                                      default:
                                                              break;
                                                      }
                                              } catch (Exception e) {
                                                      System.out.println("!!!!!!loadAllCars Error: "
                                                                      + e.getMessage());
                                                      e.printStackTrace();
                                              }
                                      }
                              }
                      }
                      return allCars;
              }
      
              public List<SelectItem> getPagesToScroll() {
                      List<SelectItem> list = new ArrayList<SelectItem>();
                      for (int i = 1; i <= allCars.size() / getRows()+1; i++) {
                              if (Math.abs(i - scrollerPage) < 5) {
                                      SelectItem item = new SelectItem(i);
                                      list.add(item);
                              }
                      }
                      return list;
              }
      
              public List<DemoInventoryItem> getTenRandomCars() {
                      List<DemoInventoryItem> result = new ArrayList<DemoInventoryItem>();
                      int size = getAllCars().size() - 1;
                      for (int i = 0; i < 10; i++) {
                              result.add(getAllCars().get(rand(1, size)));
                      }
                      return result;
              }
      
              public int genRand() {
                      return rand(1, 10000);
              }
      
              public List<DemoInventoryItem> createCar(String make, String model,
                              int count) {
      
                      ArrayList<DemoInventoryItem> iiList = null;
      
                      try {
                              int arrayCount = count;
      
                              DemoInventoryItem[] demoInventoryItemArrays = new DemoInventoryItem[arrayCount];
      
                              for (int j = 0; j < demoInventoryItemArrays.length; j++) {
                                      DemoInventoryItem ii = new DemoInventoryItem();
      
                                      ii.setMake(make);
                                      ii.setModel(model);
                                      ii.setStock(randomstring(6, 7));
                                      ii.setVin(randomstring(14, 15));
                                      ii.setMileage(new BigDecimal(rand(5000, 80000)).setScale(
                                                      DECIMALS, ROUNDING_MODE));
                                      ii.setMileageMarket(new BigDecimal(rand(25000, 45000))
                                                      .setScale(DECIMALS, ROUNDING_MODE));
                                      ii.setPrice(new Integer(rand(15000, 55000)));
                                      ii.setPriceMarket(new BigDecimal(rand(15000, 55000)).setScale(
                                                      DECIMALS, ROUNDING_MODE));
                                      ii.setDaysLive(rand(1, 90));
                                      ii.setChangeSearches(new BigDecimal(rand(0, 5)).setScale(
                                                      DECIMALS, ROUNDING_MODE));
                                      ii.setChangePrice(new BigDecimal(rand(0, 5)).setScale(DECIMALS,
                                                      ROUNDING_MODE));
                                      ii.setExposure(new BigDecimal(rand(0, 5)).setScale(DECIMALS,
                                                      ROUNDING_MODE));
                                      ii.setActivity(new BigDecimal(rand(0, 5)).setScale(DECIMALS,
                                                      ROUNDING_MODE));
                                      ii.setPrinted(new BigDecimal(rand(0, 5)).setScale(DECIMALS,
                                                      ROUNDING_MODE));
                                      ii.setInquiries(new BigDecimal(rand(0, 5)).setScale(DECIMALS,
                                                      ROUNDING_MODE));
                                      demoInventoryItemArrays[j] = ii;
      
                              }
      
                              iiList = new ArrayList<DemoInventoryItem>(Arrays
                                              .asList(demoInventoryItemArrays));
      
                      } catch (Exception e) {
                              System.out.println("!!!!!!createCategory Error: " + e.getMessage());
                              e.printStackTrace();
                      }
                      return iiList;
              }
      
              public static int rand(int lo, int hi) {
                      Random rn2 = new Random();
                      // System.out.println("**" + lo);
                      // System.out.println("**" + hi);
                      int n = hi - lo + 1;
                      int i = rn2.nextInt() % n;
                      if (i < 0)
                              i = -i;
                      return lo + i;
              }
      
              public static String randomstring(int lo, int hi) {
                      int n = rand(lo, hi);
                      byte b[] = new byte[n];
                      for (int i = 0; i < n; i++)
                              b[i] = (byte) rand('A', 'Z');
                      return new String(b);
              }
      
              public SimpleSelection getSelection() {
                      return selection;
              }
      
              public void setSelection(SimpleSelection selection) {
                      this.selection = selection;
              }
      
              public String takeSelection() {
                      getSelectedCars().clear();
                      if (getSelection().isSelectAll()) {
                              getSelectedCars().addAll(allCars);
                      } else {
                              Iterator<Object> iterator = getSelection().getKeys();
                              while (iterator.hasNext()) {
                                      Object key = iterator.next();
                                      table.setRowKey(key);
                                      if (table.isRowAvailable()) {
                                              getSelectedCars().add(
                                                              (DemoInventoryItem) table.getRowData());
                                      }
                              }
                      }
                      return null;
              }
      
              public ArrayList<DemoInventoryItem> getSelectedCars() {
                      return selectedCars;
              }
      
              public void setSelectedCars(ArrayList<DemoInventoryItem> selectedCars) {
                      this.selectedCars = selectedCars;
              }
      
              public UIScrollableDataTable getTable() {
                      return table;
              }
      
              public void setTable(UIScrollableDataTable table) {
                      this.table = table;
              }
      
              public void initColumnsHeaders() {
                      columns.clear();
                      String header;
                      String footer = "";
                      header = "Chevrolet";
                      Facet facet = new Facet(header, footer);
                      columns.add(facet);
                      header = "Ford";
                      facet = new Facet(header, footer);
                      columns.add(facet);
                      header = "Nissan";
                      facet = new Facet(header, footer);
                      columns.add(facet);
                      header = "Toyota";
                      facet = new Facet(header, footer);
                      columns.add(facet);
                      header = "GMC";
                      facet = new Facet(header, footer);
                      columns.add(facet);
                      header = "Infiniti";
                      facet = new Facet(header, footer);
                      columns.add(facet);
              }
      
              public ArrayList<DemoInventoryItem[]> getModel() {
                      if (model == null) {
                              model = new ArrayList<DemoInventoryItem[]>();
                              for (int i = 0; i < 9; i++) {
                                      DemoInventoryItem[] items = new DemoInventoryItem[6];
                                      items[0] = createCar("Chevrolet", "Corvette", 1).get(0);
                                      items[1] = createCar("Ford", "Explorer", 1).get(0);
                                      items[2] = createCar("Nissan", "Maxima", 1).get(0);
                                      items[3] = createCar("Toyota", "Camry", 1).get(0);
                                      items[4] = createCar("GMC", "Yukon", 1).get(0);
                                      items[5] = createCar("Infiniti", "G35", 1).get(0);
                                      model.add(items);
                              }
                      }
                      return model;
              }
      
              public ArrayList<Facet> getColumns() {
                      return columns;
              }
      
              public int getScrollerPage() {
                      return scrollerPage;
              }
      
              public void setScrollerPage(int scrollerPage) {
                      this.scrollerPage = scrollerPage;
              }
      
              public SortOrder getOrder() {
                      return order;
              }
      
              public void setOrder(SortOrder order) {
                      this.order = order;
              }
      
              public DemoInventoryItem getCurrentItem() {
                      return currentItem;
              }
      
              public void setCurrentItem(DemoInventoryItem currentItem) {
                      this.currentItem = currentItem;
              }
      
              public int getCurrentRow() {
                      return currentRow;
              }
      
              public void setCurrentRow(int currentRow) {
                      this.currentRow = currentRow;
              }
      
              public void store() {
                      allCars.set(currentRow, currentItem);
                      keys.clear();
                      keys.add(currentRow);
              }
      
              public void delete() {
                      allCars.remove(currentRow);
              }
      
              public Set<Integer> getKeys() {
                      return keys;
              }
      
              public void setKeys(Set<Integer> keys) {
                      this.keys = keys;
              }
      
      }