aspose file tools*
The moose likes JSP and the fly likes How to show current date and month of system using JSTL tag on JSP by drop down field as default? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to show current date and month of system using JSTL tag on JSP by drop down field as default?" Watch "How to show current date and month of system using JSTL tag on JSP by drop down field as default?" New topic
Author

How to show current date and month of system using JSTL tag on JSP by drop down field as default?

Vinod Vijay
Ranch Hand

Joined: Sep 13, 2011
Posts: 137

Hi, on my JSP there are three different drop down fields each for
1) dd
2) mm
3) yy

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.

Please suggest






Vinod Vijay Nair
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 917
    
  13

It sounds to me like you are making way too much work for yourself. Why not just use something like DatePicker?




"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
Vinod Vijay
Ranch Hand

Joined: Sep 13, 2011
Posts: 137

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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61054
    
  66

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to show current date and month of system using JSTL tag on JSP by drop down field as default?