This discussion is archived
3 Replies Latest reply: Nov 27, 2012 5:05 AM by aksarben RSS

how to create cascading dropdownlist in java

975834 Newbie
Currently Being Moderated
hi,

i am new to java ,i have a employee table that has feilds id,name state city and area. now i have to access employee name based on state city area .i have written console program that displays employee info based on id .now i want a way to acess name by state city and area.ie my program should ask state when i provide state it should display all cities in that state ,then when i select city it should display all area in that city then when i select area it should display all emp name from that area



import java.util.ArrayList;
import java.io.*;

public class Employeelookup {
     
static ArrayList<Employeelookup> al = new ArrayList<Employeelookup>();
int id;
String name;
String State;
String city;
String Area;

static int count = 0;
{
}
Employeelookup()
{
}
Employeelookup(int id, String name, String State,String city,String Area)
{
this.id = id;
this.name = name;
this.State=State;
this.city=city;
this.Area=Area;

count++;
}
public void SetId(int id)

{
     this.id=id;
}
public int getId()
{
     return id;
}
public void SetName()
{
     this.name=name;
}


public void putDetails(Employeelookup e)
{
al.add(e);

}

public Employeelookup getDetails(int id)
{
Employeelookup es = (Employeelookup)al.get(id);
return es;
}

public static void main(String[] args ) throws IOException
{
     
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

Employeelookup e = new Employeelookup();
Employeelookup e1 = new Employeelookup(1, "SaiRam", "karnataka","bangalore","rajajinagar");
Employeelookup e2 = new Employeelookup(2, "Anu", "karnataka","mysore","temple road");
Employeelookup e3 = new Employeelookup(3, "Vasu", "karnataka","bangalore","rajajinagar");
Employeelookup e4 = new Employeelookup(4, "Shillu", "Tamil Nadu","madhurai","b");
Employeelookup e5 = new Employeelookup(5, "Madhu", "Karnataka","shimoga","bus stop");
Employeelookup e6 = new Employeelookup(6, "Volga", "Andra","abc","railway stop");


e.putDetails(e1);     
e.putDetails(e2);
e.putDetails(e3);
e.putDetails(e4);
e.putDetails(e5);
e.putDetails(e6);

System.out.println("The total number of Employeelookups are: " +count);
System.out.println(" ");

while(true)
{
System.out.println("Enter Employeelookup id to get the Employeelookup details: ");
int id = Integer.parseInt(br.readLine());
boolean flag = false;


for(int i=0; i <al.size();i++)     {
Employeelookup es = e1.getDetails(i);
if(id == es.id)
{
System.out.println("The details of the Employeelookup with id " id " is: ");
System.out.print(es.id +" " es.name" " es.State" " + es.city+" " es.Area" "+"" );
flag = true;
break;
}
}

System.out.println(" ");

if(!flag)
{
System.out.println("Sorry, no data exists with the id " +id);
}
System.out.println(" ");
String ch = null;

while(true)
{
System.out.println("Want to Continue(y/n)?)");
System.out.println(" ");
ch = br.readLine();
if(ch.equalsIgnoreCase("y") || ch.equalsIgnoreCase("n")) break;
if(!(ch.equalsIgnoreCase("y") || ch.equalsIgnoreCase("n")))
{
System.out.println("Invalid option : please type y/n");
System.out.println(" ");
}
}

if(ch.equalsIgnoreCase("n"))
{
System.out.println(" ");
System.out.println("Thank you");
break;
}
}
}
}

Edited by: 972831 on Nov 22, 2012 10:50 PM
  • 1. Re: how to create cascading dropdownlist in java
    Kayaman Guru
    Currently Being Moderated
    972831 wrote:
    now i want a way to acess name by state city and area.ie my program should ask state when i provide state it should display all cities in that state ,then when i select city it should display all area in that city then when i select area it should display all emp name from that area
    Well, where are you stuck? Take the input and see if it's "state", "city" or "area". Then read another input for its name. Then go through all the items you have and check whether there's a match.
  • 2. Re: how to create cascading dropdownlist in java
    975834 Newbie
    Currently Being Moderated
    I have created this class now i want my program to print

    id and name

    based on state city and area ie. i should use this existing class then loop through state city area to get the id and name :like in certain web application we select state city and area then it displays pincode of these combination.
  • 3. Re: how to create cascading dropdownlist in java
    aksarben Journeyer
    Currently Being Moderated
    Without even examining the details of your code, IMHO it's far too long for one method. Break it into smaller, manageable chunks. Who knows? The solution might even jump out at you while you're doing that.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points