Filtering a Vaadin SQL Container
My previous post concerning the Vaadin SQL Contanier covered how to create a SQL Container and a Table Query using the Vaadin SQL Container Add On.
In this post I will give a very short overview on how to filter the results of a Table Query.
A filter can be applied to a SQL Container so that the results of that Table Query can be narrowed to a specific set of rows within the table.
For example, lets assume you have created a Table Query on an address table within your database.
Your requirement is to filter the data within that Table Query to a specific suburb, street and postcode.
To achieve that requirement you create three filters using the Compare.Equal object. The values for suburb, postcode and street are passed in as parameters.
You then create a SQLcontainer and then add the filters using the "And" filter. This ensures that the selected rows will match the comparisons you established using the "equal" filters.
Nice and simple.
In this post I will give a very short overview on how to filter the results of a Table Query.
A filter can be applied to a SQL Container so that the results of that Table Query can be narrowed to a specific set of rows within the table.
For example, lets assume you have created a Table Query on an address table within your database.
TableQuery q = new TableQuery("address", connectionPool);
Your requirement is to filter the data within that Table Query to a specific suburb, street and postcode.
To achieve that requirement you create three filters using the Compare.Equal object. The values for suburb, postcode and street are passed in as parameters.
Compare.Equal suburbFilter = new Compare.Equal("suburb", suburb);
Compare.Equal postcodeFilter = new Compare.Equal("postcode", postcode);
Compare.Equal streetFilter = new Compare.Equal("street", street);
You then create a SQLcontainer and then add the filters using the "And" filter. This ensures that the selected rows will match the comparisons you established using the "equal" filters.
SQLContainer addressContainer = new SQLContainer(q);
addressContainer.addContainerFilter(new And(streetFilter, suburbFilter, postcodeFilter))
;Nice and simple.
Comments
Post a Comment