FilterBuilder used for building query string?

I am using SmartGWT 2.4.

Can I use the filter builder to build a query string?

I want to be able to use the dynamic ability of the FIlterBuilder to create criteria and subclauses but not have it the underlying set of filters applied to a set of records or database?

I want to be able to get the Advanced Criteria from a FilterBuilder to build the where clause of a SQL statement.

Is this possible to do are there any problems to doing this? How do I construct the datasource for the filter builder?

Thanks, Any help would be appreciated.

Be sure your post includes:

  1. the SmartGWT or SmartClient version and browser version(s) involved;

  2. for a server-side problem, the complete logs generated during processing of the request;

  3. for a client-side problem, the contents of the Developer Console (see FAQ for usage);

  4. if there is a JavaScript error, the stack trace logged in the Developer Console (from Internet Explorer if possible); and

  5. sample code.

Posts with incomplete information are much more likely to be ignored.

First, are you aware that the SmartGWT server already does this (and does it very very well, with lots of customization hooks?). If not, see the QuickStart Guide, Server Framework chapter.

Also, are you trying to do this client-side or server-side? Targetting what database engine?

Hello,

I will know nothing about the database. I am to use a web service that accepts a string containing a sql like where clause amd returns results in xml form. That is the requirement, unfortunately and I have to work within those parameters. No other UI component I have found is as nicely done as SmartClient’s filterbuilder and I wanted to leverage that as part of my web app.

How would I set the different fields within the FilterBuilder? Can this even be done successfully without having the “usual” DataSource that populates the filter builder?

Makes sense, however you probably do want to do this via a DataSource (just as easy and allows for more features). However which are you trying to use: SmartClient or SmartGWT?

Sorry I meant to say I am using SmartGWT. I am currently experimenting with creating the DataSource and trying pass it to the FilterBuilder. Although I have found while creating the FilterBuilder that setMatchAnyTitle, setMatchAllTitle, setMatchNoneTitle doesn’t it seem to change the Match Any, All, etc… text in the filter builder drop down. Also, I continuallyget the error:

Fields cannot be added to a DataSource after the underlying component has been created.

This is my code:

<CODE>

	DataSourceField field = new DataSourceField("Genre",FieldType.TEXT, "Genre");
	field.setValidOperators(OperatorId.EQUALS);
	field.setValueMap("SPORTS", "HORROR");

	DataSource ds = new DataSource();
	ds.setClientOnly(true);
	ds.setTypeOperators(null, new OperatorId[]{OperatorId.AND, OperatorId.OR});
	ds.setFields(field);

	FilterBuilder fb = new FilterBuilder();
	fb.setMatchAllTitle("AND");
	fb.setMatchAnyTitle("OR");
	fb.setDataSource(ds);

</CODE>

That error about fields is caused by trying to setFields() or addField() after you’ve called setDataSource() on some component with the DataSource, which is not allowed since the component needs a stable DataSource definition to do it’s job.

As far as forming your SQL string, you can do this either server-side or client-side but it’s typically easier server-side. In both cases you’re working with a Java AdvancedCriteria object and you just need to recursively traverse it generating the appropriate SQL for each Criterion.

Server-side you get it from the DSRequest.getAdvancedCriteria() from inside a DMI - see the QuickStart Guide for an overview of DMI and how you can then use standard Java server libraries to contact the web service where you need to send the SQL. Note, you should download the latest nightly (from smartclient.com/builds) since a lot of new docs and helper methods were added in this area since 2.4.

Thanks for the great support!

BTW… I found out that in order to avoid the error mentioned previously (“Fields cannot be added to a DataSource after the underlying component has been created”), I have to do a setID to some arbitrary id string before using setField.

Does this seem right to you?