Software design dilemma - flexible search results?

T

timasmith

Hi,

There must be a better way than I am doing this - not really language
specific but here is the problem stated in java like pseudo code:

I want to have user defined search results for common search
functionality.

I have search functionality provided as a service, which currently
returns an object lets say like the following (plus getters/setters):
public SearchResult {
private int id;
private String name;
private String location;
private Calendar birthDate;
}
public SearchResultList extends Vector {
...
}

I also have a database table which holds the users custom columns they
would like to list in their results
create table searchOption ( userid number, String name);
insert into searchOption values (1,'location');
insert into searchOption values (1,'birthDate');

So when the user searches I have

SearchResultList list = service.getSearchResults(criteria);

What I currently do which is very clumsy

FieldList fields = service.getUserFieldOptions(userid);

DefaultTableModel table = new DefaultTableModel();
// iterate through the fields and add columns

Enumeration e1 = list.elements();
while (e1.hasMoreElements()) {
SearchResult result = (SearchResult) e1.nextElement();
Vector datavalues = new Vector();
Enumeration e2 = fields.elements();
while (e2.hasMoreElements()) {
Field field = (Field) e2.nextElement();
if (field.getName() == "name")
datavalues.add(result.getName());
elseif (field.getName() == "birthdate")
datavalues.add(result.getName());
etc.
}
table.add(datavalues);
}

// finally display the tablemodel
 
T

Tris Orendorff

(e-mail address removed) burped up warm pablum in


Not an answer to your dilemma but:
if (field.getName() == "name")
should probably be:

if (field.getName().equals("name"))














--

Sincerely,

Tris Orendorff
[Two antennae meet on a roof, fall in love and get married. The ceremony
wasn't much, but the reception was excellent.]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,844
Latest member
JudyGvh32

Latest Threads

Top