Hi there! I'm realllyyyy getting confused..

I'm trying to create a table with the resultSet from a mysql database (I
tried DataView but gave up..too much for me) by using a ListView. The
problem is that I keep getting an ClassCastException: java.lang.String. 
Wicket tells me this happens in the populateItem() method when I try to cast
the ListItem to User (of course..). I have a simple User class with getters
to retrieve: int userid, String name, String phone, etc...I don't know why
this is happening so..could someone please help? 

Thanks in advance,
Edd


[CODE]

        ....
        
        /* create connection do mysql db and retrive a ResultSet */
        NewConnection myconn = new NewConnection();
        final ResultSet userTableData = myconn.queryTable("SELECT * FROM
user");
        
        /* calling method that transforms my ResultSet (usersList) to a List
*/
        List usersList = getUsers(userTableData);
                
        ListView listView = new ListView("pageable", usersList)
        {
            protected void populateItem(ListItem listItem)
            {
                User user = (User)listItem.getModelObject();  //
CLASSCASTEXCEPTION HEREEE
                listItem.add(new Label("userid",
Integer.toString(user.getUserId())));
                listItem.add(new Label("name", user.getName()));
                listItem.add(new Label("phone", user.getPhone()));
                listItem.add(new Label("email", user.getEmail()));
                listItem.add(new Label("type", user.getType()));
            }
                
        };
        add(listView);


        .....

        /* method to convert ResultSet to List */
        public List getUsers(ResultSet rs) {
             List retval = new ArrayList();
             try {
                while(rs.next()) {
                    retval.add(rs.getString(1));    
                }    
             } catch (SQLException ex) {
                 ex.printStackTrace();
            }    
        return retval;
        }
        
-- 
View this message in context: 
http://www.nabble.com/ListView-class-cast-exception-tf3807874.html#a10777112
Sent from the Wicket - User mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to