Java
  Home arrow Java arrow Page 2 - Creating a User Interface for a Search Ser...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Creating a User Interface for a Search Service
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2006-11-22

    Table of Contents:
  • Creating a User Interface for a Search Service
  • Changes to the Original Code to Fit the JSP
  • Setting Up the Indexer
  • Making Use of the Configuration Service

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating a User Interface for a Search Service - Changes to the Original Code to Fit the JSP


    (Page 2 of 4 )

    JSP reflects on fields to hook up properties to <out> display tags instead of getters and setters. Unfortunately, our original implementation of HitBean marked all of its data private and only exposed getters and setters (normally, the appropriate strategy). Since we now have to have the fields exposed directly, we need to make a simple change to the Spider. The original class started with these declarations:

      final String url;
      final String title;
      final float score;

    It now has to become:

      public final String url;
      public final String title;
      public final float score;

    What if We Don’t Have the Spider Source?

    It is instructive to examine what happens when we aren’t the original authors of either the application we are extending (jPetStore) or the service we are integrating (Simple Spider). If we don’t have access to the source code of either project, we can still make the extension we’ve been working on. For the jPetStore, all we did was modify a configuration file and a JSP (which we always have the source for) and add a new class.

    If we don’t have access to the original source for theHitBeanclass, how can we make it work with the JSP? The answer is simple: write a wrapper class that exposes the correct properties (or just use the already exposed web service interface):

      public class HitBeanWrapper {
         private HitBean _hitbean;
         public String url;
         public String title;
         public float score;

         public HitBeanWrapper(HitBean hitbean)
         {
            _hitbean = hitbean;
            url = hitbean.getUrl();
            title = hitbean.getTitle();
            score = hitbean.getScore();

         }
         public String getScoreAsString() {
                 return _hitbean.getScoreAsString();
         }
      }

    This requires a change to thehandleRequestmethod of theSearchPagesController, as well:

      HashMap hits = new HashMap(qb.getResults().length);
      for(int i =0;i<qb.getResults().length;i++)
      { 
          
    hits.put("hits", new HitBeanWrapper(qb.getResults()[i]));
      }
      return new ModelAndView("SearchProducts", hits);

    That’s it. We’ve edited the Spider all we need to in order to incorporate it into thejPetStoreapplication.

    Principles in Action

    • Keep it simple: display the URL to result pages instead of complex rendering of product information; use simple table output instead of PagedListHolder (the need for it was gone)
    • Choose the right tools: table, not PagedListHolder; JSP
    • Do one thing, and do it well: JSP focuses on display of output, not search intricacies
    • Strive for transparency:HitBean exposes simple data properties; use a wrapper forHitBeanif the source is not available
    • Allow for extension: none

    More Java Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Better, Faster, Lighter Java," published...
     

    Buy this book now. This article is excerpted from chapter 10 of the book Better, Faster, Lighter Java, written by Bruce A. Tate and Justin Gehtland (O'Reilly; ISBN: 0596006764). Check it out today at your favorite bookstore. Buy this book now.

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT