Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Software design dilemma - flexible search results?

Thread view: 
timasmith@hotmail.com - 17 Jan 2006 03:08 GMT
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.