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
Tris Orendorff - 20 Jan 2006 15:32 GMT
Not an answer to your dilemma but:
> if (field.getName() == "name")
should probably be:
if (field.getName().equals("name"))

Signature
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.]
Roedy Green - 20 Jan 2006 22:21 GMT
> elseif (field.getName() == "birthdate")
there is no elseif keyword in Java. Further that is not how you
compare strings in Java . See
http://mindprod.com/jgloss/gotchas.html#COMPARISON

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.