Advertisement

02.01.2008 at 08:51AM PST, ID: 23130070
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Does anyone know how to populate a jTable from a hibernate List?

Tags: Java
Does anyone know how to populate a jTabel from a Hibernate List? I've tried to create my own TableModel, but am getting CastException when trying to cast the item.. example
public class HibernateTableModel implements TableModel
{
 List datalist;             // The ResultSet to interpret
 
  int numcols, numrows;          // How many rows and columns in the table
  String [] cols = {"ID", "Claim No", " Last Name", "Serial No", "Model No"};

  /**
   * This constructor creates a TableModel from aList.  It is package
   * private because it is only intended to be used by
   * TableModelFactory, which is what you should use to obtain a
   * TableModel
   **/
  public HibernateTableModel(List datalist) throws SQLException
  {
    this.datalist = datalist; // Save the results
    // Get metadata on them
    numcols = getColumnCount(); // How many columns?                        
    numrows = getRowCount(); // How many rows?
  }
 
 
  public void addWidgetList(List l)
  {
    datalist.addAll(l);
    fireTableDataChanged();
  }
  /** Automatically close when we're garbage collected */
  protected void finalize() {  }

  // These two TableModel methods return the size of the table
  public int getColumnCount() {
     numcols = cols.length;
   return numcols;
   }
   
  public int getRowCount() {
    numrows = datalist.size();
  return numrows;
  }
 
  public String getColHeader(int column) {
      return cols[column];
  }

  // This TableModel method returns columns names from the ResultSetMetaData
  public String getColumnName(int column) {
    return cols[column];
  }

  // This TableModel method specifies the data type for each column.  
  // We could map SQL types to Java types, but for this example, we'll just
  // convert all the returned data to strings.
  public Class getColumnClass(int column) { return String.class; }
 
 
  public WarrantyClaimBean getWidgetAt(int row)
  {
      Object obj = datalist.get(row);
    return (WarrantyClaimBean) obj;
  }
  /**
   * This is the key method of TableModel: it returns the value at each cell
   * of the table.  We use strings in this case.  If anything goes wrong, we
   * return the exception as a string, so it will be displayed in the table.
   * Note that SQL row and column numbers start at 1, but TableModel column
   * numbers start at 0.
   **/
  public Object getValueAt(int row, int column) {
   System.out.println(Integer.toString(row));
   Object value;
    WarrantyClaimBean widget;
    widget = getWidgetAt(row);
    switch (column)  
   {
      case 0:
         return Long.toString(widget.getRecId());
      case 1:
         return widget.getClaimNo();
      case 2:
         return widget.getLastName();
      case 3:
         return widget.getSerialNo();
      case 4:
         return widget.getVacModel();
      default:
         return null;
   }
  }

  // Our table isn't editable
  public boolean isCellEditable(int row, int column) { return false; }

  // Since its not editable, we don't need to implement these methods
  public void setValueAt(Object value, int row, int column) {}
  public void addTableModelListener(TableModelListener l) {}
  public void removeTableModelListener(TableModelListener l) {}

  private void fireTableDataChanged()
  {
  }
}

Any help would be appreciated.
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: jlowe1268
Solution Provided By: dejanpazin
Participating Experts: 2
Solution Grade: A
Views: 4
Translate:
Loading Advertisement...
02.02.2008 at 12:28AM PST, ID: 20803715

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.02.2008 at 02:31AM PST, ID: 20803923

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29 / EE_QW_2_20070628