Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Linked Drop Down Lists  RSS feed

 
Black Fox
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, this is my first post and I would like to apologize in advance for any specific forum etiquette that I may fail to observe.

I have been working, as a term project, on a web application that is based on the three tier model (JSP - Web Server Frontend (GlassFish) / Controller (Java Servlets) / Database (mysql)). The application is meant to manage the summer internships program of an imaginary university. I knew nothing about Servlets and Web Development prior to starting this project (the course is actually on databases), and I have been figuring out my way as I go so far.

The difficulty I am currently having is in creating what I believe are called 'Linked Drop Down Lists'. There will be an interface for adding a new 'Quota' to the system. A quota is associated to a 'business unit' of one of the registered 'companies'. Of course, ultimately this information will be transmitted to a servlet via a form. What I want is to have two drop down lists, one for companies and the other for business units. Selecting a particular business unit should alter the available options in the 'units' list - since each company has a different list of units.

Searching the web I came across a ton of different approaches - mostly involving loads of JavaScript - that I couldn't make much sense of.

I am pretty confused about how I should approach this problem. I would very much appreciate it if someone could at least point me in the right direction. How would such a system work? Is JavaScript necessary? Can I handle everything in a single JSP page? Do I need a standalone servlet? Do I need a Java Bean to keep track of the state? etc. etc.

Many Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The most common means to do this is with JavaScript and Ajax. You could do it with just JSP -- but you'd have to resubmit the whole page and redraw it with the new values for the secondary dropdown. This is an approach that would have been taken in 2002 or so before the advent of Ajax technology.

So it all depends on how modern an approach you want to take.
 
Black Fox
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You Bear Bibeault. It seems I will be doing some reading on Ajax. Is there any learning path you can suggest that would be appropriate for my problem?

Also your reply resolved one gigantic point of confusion I have been having which was how I would handle all the redrawing. However, there is still something I am not quite sure about. As I mentioned, my database is an external mysql database. Is is possible to query this database from within a JSP page without redrawing (when someone changes the company selected), or should all the company - unit data be imported into the page and dynamically filtered instead?

Thanks Again
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Black Fox wrote:Is is possible to query this database from within a JSP page without redrawing
No. JSP executes on the server in order to format the HTML to send to the browser. Once dispatched, that generated HTML page is all you get.

And... no operations, such as database access, should ever be done in a JSP at all. That's a really poor practice that's been discredited for almost a decade.

You might benefit from reading this article and this article.
 
Black Fox
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Bear Bibeault,

I managed to get it working using Ajax. I wrote a JS Script that reloads the page with the company name as a query parameter, which is then used to populate the units list through JPA.

Furthermore, I was able to tidy up my application alot by following the guidelines found in the links you sent me.

Thanks for the valuable input!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!