• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

auto complete to DB

 
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to make a select list of city and state in jsp. I want both select lists to have auto complete. Do I need to use third party UI?
secondly, the value of selected state will automatically change the value selected in the city select list. Does this mean I need to query to DB everytime state is changed? FYI, city and state are both stored in DB where one state has at least one city.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is nothing in JSP to create autocompleters. I'll move this to the HTML/JavaScript forum.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a bazillion autocomplete widgets out there. Do a search.

One of the more popular is the jQuery UI autocompleter.
 
Hendra Kurniawan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the best practice to populate the select list? the city and state is recorded in database. do you reload the contents of the selects everytime it's changed? about the autocomplete, I assume the list of possible matches changes as we type into the field, does that mean DB hit everytime a new character is typed in?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All of that greatly depends upon which autocompleter implementation you choose. Some only have one way to do things, so that's the way you have to do it.

One of the reasons that the jQuery UI autocompleter is popular is that it has numerous ways to load the data that you can choose from to best match your requirements.
 
Hendra Kurniawan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay, let's say I'll use the jquery for this, how do I do it? I assume you've had experience with this, so you recommend it to me. Based on your experience, what's the best way to communicate between the jsp and DB. I don't know if I asked this in coderanch or not, how do you transfer the data from DB to JSP? in what form? resultset? object? XML? JSON? or other?

[EDit: cross-post to alternate question removed]
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You haven't given enough information to be able to answer that.

But in general, a resultset should never be sent anywhere. Any data in a resultset should be copied to a collection and the result set closed as soon as possible.

So what are you requirements? Do you need to fetch the data in real time? Is it known at the time that the page loads? Other?
 
Hendra Kurniawan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
normally in my days as desktop app developer using VB6, the content of dropdown is refreshed (DB is queried and the dropdown is re populated) each time the user drop it down (you know, clicking that small down arrow button in the left most of the dropdown, I dont know how to describe the action). that way the values displayed in the dropdown control is guaranteed to be updated for latest changes. I assume this won't be the case for web app, since the overhead will be too great. using jquery, is it recommended to hit the DB everytime the dropdown is "dropped" by user? or when the autocomplete is in the play, DB hit every time user type in character into the field? what information do you need? I hope that's what you asked. In essence, I want to know when to hit DB. Just when the page loads (if this is the case, then if the page never reloads, the dropdown won't get updated). the jsp will consist of only two controls, the dropdown and imagebox. the image will be updated according to selected value in the dropdown.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hendra Kurniawan wrote:I assume this won't be the case for web app, since the overhead will be too great.


Premature optimization. How do you know that until you try it? I routinely fetch things in real time (using jQuery and Ajax).

is it recommended to hit the DB everytime the dropdown is "dropped" by user?


As with any other question, the answer is "it depends". Is the data static? Then no. Does the data change? If so, how often? Daily? Hourly? Every millisecond?

 
Hendra Kurniawan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as of now, perhaps it's static. in short, the data of state and city won't change very frequently (well, unless some state secedes or the country conquered and claim other country's cities as their own). because the data rarely change, dropdown reloaded every page load event I assume?
as of now, the number of city and states are not that many, but I'm curious, let's say there are 1 million values from DB, how do you do this? you copy all 1 million to object and send it to jsp? or paging? if paging, how to synchronize paging with jquery ?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the data isn't going to change, read it once in a context listener and cache it in application scope. It'd be ludicrous to hit the DB on every page display for data that isn't going to change.

Millions of entries is way too large to show in its entirely so that situation is completely different. When the data is too large to cache, the autocompleter should likely obtain the data dynamically using the filtering capabilities of the DB. Why grab millions of entries when we know that we only need the ones that star with "F"?
 
Hendra Kurniawan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You said filtering, and let's use your example, start with F. what happens if there are 100 thousand rows starting with F (out of the 1 million rows)? you grab 100 thousand from app cache?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the case of really large data sets, usually the autocompleter won't "start" until a few characters have been typed in order to keep the number of choices presented down. Typically three of more characters.
 
Hendra Kurniawan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but you still need to load the entire 100 thousand row to jsp? partial load is impossible right? by partial load I mean like paging, so when the dropdown is scrolled down, DB is hit as needed.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've never seen paging inside an autocompleter. I have no idea how that would even make sense. Paging is usually used to slice a large data set for display on the page.
 
reply
    Bookmark Topic Watch Topic
  • New Topic