Tobi123 Tobi123 - 3 months ago 19x
MySQL Question

Vaadin ValueChangeEvent getProperty for specific table column

I'm using Vaadim und MySQL DB. I visualized a table of my DB (only one column) as a table and I want to click the table rows and retrive the value of a specific column when a click at single row.

//Database Connection Class
private SQLContainer catExtractionContent = null;
FreeformQuery catExtractionQuery = new FreeformQuery("Select name as HAUPTKATEGORIE from Category where cat_main is null", connectionPool);
catExtractionContent = new SQLContainer(catExtractionQuery);

private Object mainCatname=null;
mainCatTable = new Table();
mainCatTable.setContainerDataSource(getDBConn().getcatExtractionContent()); //This retrieves the SQL Container from obove
mainCatTable.addListener(new ValueChangeListener() {

public void valueChange(ValueChangeEvent event) {
mainCatname = event.getProperty().getValue();

My Table contains Category namens.

The System.out.println prints 1,2,3...when I click first, secound, third row at my table in the browser.
HOW can i set to get the column "name" / "HAUPTKATEGORIE"???

I was trying the whole day but I was not successful.


you have to read from the containerproperty the content of the columns. For this you need the propertyId. in your case propably "name" or "HAUPTKATEGORIE". i am not sure how the SQLContainer works.

mainCatTable.addValueChangeListener(new ValueChangeListener() {

    public void valueChange(ValueChangeEvent event) {

        Property<Table> p = event.getProperty(); //property of valuechangeevent in this case the Table instance
        Object itemId = p.getValue(); //selected item in table. also known as "itemId"

        Property<?> containerPropertyName = mainCatTable.getContainerProperty(itemId, "HAUPTKATEGORIE");
        System.out.println("HAUPTKATEGORIE : " + containerPropertyName.getValue());