File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes filtering values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "filtering values " Watch "filtering values " New topic
Author

filtering values

alex pandiyan
Greenhorn

Joined: Aug 25, 2004
Posts: 10
Hi all,
can you suggest some good validation technique for the following prob:
say if there are 3 combo,continent,country,state.The user selects any values in the 3 combo.Clicks submit.
After submission,i have to display data .
If particular state is not in the particular country,or if he selects all states,i have to display countries present in the continent and countries not present in the continent,like that.
Am new to java.
any suggestion would be nice.
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Alex,

A few suggestions:
  • Force the user to select continent first, then country, then state/county/province/region or whatever. When continent is selected, either submit automatically or (best practice re usability) force the user to press a submit button. Populate the country list box with only countries appropriate to the selected continent. When a country is selected repeat for states. The most effective way to store these continent/country/state relationships is probably in a relational database on the server.
  • Allow the user to select what they want in the 3 boxes and check that the 3 selections are a valid combination against the relationships stored in your database, i.e. is country in continent; is state in country?
  • Retrieve all the continent/country/state combinations to the client side when the page loads (probably not a great idea as there will be a lot of data) and manipulate the contents of the subordinate dropdowns, using DHTML and JavaScript, according to the selection made by the user. This method works quite well if there are not too many combinations and you want to eliminate the overhead of multiple submits.


  • Do these suggestions help you to decide how you want to handle this?

    Jules
    alex pandiyan
    Greenhorn

    Joined: Aug 25, 2004
    Posts: 10
    Julian,
    Your suggestions really gave me some good ideas of how to do things.
    But,what if i am not using a database,say am reading it from some file and populating it in some objects.
    I have all states in one object,all continent in one object and all countries in one object.
    How to do the jsp validation?
    How to display them in jsp?
    Any code sample would be more helpful.
    Thanks in advance.
    Julian Kennedy
    Ranch Hand

    Joined: Aug 02, 2004
    Posts: 823
    Alex,

    I'm not going to write your code for you, and it's unlikely you'll find anyone else to do that on this site either. I am, however, prepared to help you with the design of your application and point you in the right direction as to how to code it.

    You need to know which countries belong to each continent and which states belong to each country. It's no good having an object containing all the continents, one containing all the countries and a third containing all the states with no relationship between them. Do you see what I mean?

    If you're still not sure, perhaps you could post a small fragment of your code (using the UBB CODE tags) so that I can see what you're doing.

    Jules
    alex pandiyan
    Greenhorn

    Joined: Aug 25, 2004
    Posts: 10
    Hi Jules,
    Thanks for your tip.
    My sample code is:
    <select name="state">
    <%
    ArrayList stateAl=(ArrayList)session.getAttribute("State");
    int size=stateAl.size();

    %>
    <%
    for(int i=0;i<size;i++)
    {
    String states=(String)stateAl.get(i);
    %>
    <option value='<%=states%>'><%=states%></option>
    <%}%>

    Like the same way i am loading the other 2 combos.

    My problem is how to do the validation,i.e,,separate the available states for the particular country and unavailable states for the particular country.

    Thanks in advance jules.
    Julian Kennedy
    Ranch Hand

    Joined: Aug 02, 2004
    Posts: 823
    OK, so you have 3 ArrayLists; one for each of Continents, Countries and States. How do you know, from the data you have, which countries belong to which continents?

    Jules
    alex pandiyan
    Greenhorn

    Joined: Aug 25, 2004
    Posts: 10
    I don't have any relationship between them.I think that is absurd to have like that.You really have a valid point in your question jules.
    My combo population is wrong.
    I have to design someway around.
    Julian Kennedy
    Ranch Hand

    Joined: Aug 02, 2004
    Posts: 823
    You got it. Feel free to post again if you have trouble designing/implementing something suitable.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: filtering values