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
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