Get whole table row

Hi All!
I have a table where every row is a specific Class (AgentPing).
I need get whole row (with all columns) when i click selected row.
How can i do that?

Here is a piece of code:

BeanItemContainer<AgentPing> beans = new BeanItemContainer<AgentPing>(
                AgentPing.class);
try {
            String sql = 
                    "select id_agent, nm_agent\n" +
                    "  from mq_agents";
            Connection conn = getDbConnection();
            //in.put(":id_agent", "16332");
            List<BasicDynaBean> rows = null;
            rows = conn.execQuery(sql);
            if (rows != null && !rows.isEmpty()) {
                Iterator<BasicDynaBean> iterator = rows.iterator();
                while (iterator.hasNext()) {
                    BasicDynaBean row = iterator.next();
                    AgentPing agentPing = new AgentPing();
                    agentPing.setNmAgent((String) row.get("nm_agent"));
                    agentPing.setIdAgent((Number) row.get("id_agent"));
                    // Hree is I add filled class to bean
                    beans.addBean(agentPing);
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        
table = new Table("Список Агентов-Kosmos", beans);
table.addListener(new Property.ValueChangeListener() {
            public void valueChange(ValueChangeEvent event) {
                Object selectedRow = table.getValue();
                // Here i need to convert from selectedRow to my Class
            }
        }); 

Object selectedRow should be the selected AgentPing object

Wolfgang Wachsmuth! Could you please give example for complete understanding…

Hi Alexander,

here a very simple example:

final Table myTable = new Table(); BeanItemContainer<AgentPing> myDataSource = new BeanItemContainer<>(AgentPing.class); List<AgentPing> myAgentPings = loadAgentPingsFromDataBase(); for (AgentPing myAgentPing : myAgentPings) { myDataSource.addBean(myAgentPing); } myTable.setContainerDataSource(myDataSource); myTable.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { handleThis(myTable.getValue()); } }); Your method handleThis() has as parameter an AgentPing object or null and is the currently selected value/item of your table

Thanks Wolfgang)
Your example helped me)), but more right way to rich the whole row is:

table.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { Set<AgentPing> value = (Set<AgentPing>) table.getValue(); for (AgentPing item : value){ item.getNmAgent(); } } }); I think this will be helpful someone…