Hi, on my JSP there are three different drop down fields each for
I want to populate data in each of these fields. For year field, Im successfully able to achieve it because the condition was to populate current year onwards only like for e.g. - year drop down field will have the current year say 2012 plus future 20 years data so it was easy. To achieve this what I did. I created a utility class and wrote a method which returns the system's current year then using for loop I iterate upto 20 and added to current year and put all these data into a list and returned this list on to jsp. Using <c:foreach> I started iterating and it is coming well. Default value is 2012(current year)..
I can do the same thing for date and month drop down fields also but list will store all those objects by insertion order and my current date will be not be top of all objects. Please suggest me some collection to have my object first then other following it. For e.g Current date and month is 29th Oct, then I want first collection(for date) to store in order like 29, 30, 31, 1, 2, 3, -------28. And for month it should be like, 10, 11, 12, 1, 2, ,3,----9.
So that I can simple call these collections on JSP where user will have current date, month, year as pre-populated inside drop down fields on screen loads where he can change it also to something else.
I hope you got my point.
Secondly, creating different collections for dd, mm, and yy is fine? Is my approach okay or better approach you have? Because what I feel is that if I create 3 different then I have to put strong validations also to prevent user selecting a date like 31 Nov 2012 and submitting the form.
Jk Robbins wrote:It sounds to me like you are making way too much work for yourself. Why not just use something like DatePicker?
I tried hell lot of with Jquery date picker since last 4days but it is not coming up. I'm using bootstrap also. So I think jquery and bootstrap css classes are clashing with eachother as a result no date picker is coming but only ordinary text box.
I'd use the jQuery datepicker as well. It's pretty easy to use.
But if you insist on using the dropdowns, you do not need to order the values in a wonky fashion so that the first option is selected. Rather, put the values in a reasonable order and use the selected attribute on the option that is to appear selected