You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Sy...@swisscom.com on 2003/03/28 11:08:02 UTC

How to manage criteria entries

Hello,

I'm working on a Search web form and I'm using OJB to retrieve data from my database.

I have three criteria on my form:
- name (String)
- dhcp (boolean)
- status (int)

The user has 2 choices: enter a data in the form fields or not.

I want to retrieve:
-> all (no criteria in the query) if there is nothing in the form field.
-> the data considering the criteria entered in the form field if there is one.

The code is
----code----
Criteria crit = new Criteria();
crit.addEqualTo("name", this.getName());
crit.addEqualTo("dhcp", new Boolean(this.getDhcp()));
crit.addEqualTo("status", new Integer(this.getStatus()));

Query query = new QueryByCriteria(Workstation.class, crit);

Collection toBeEdited = broker.getCollectionByQuery(query);
...
----code----

A problem occurs when there are nothing in the form fields, then OJB try to find data that have nothing in their fields instead of all the data.

Is there an "OJB" solution to do:

if field = ""
  then field = "%"


Thanks
Sylvain