I want to use a JSTL c:foreach loop.<c:foreach>
The loop should start with the current year and end with current year-100(2011 to 1911).
I used scriptlets for begin and end tag
//
SimpleDateFormat simpleDateformat = new SimpleDateFormat("yyyy");
int year = Integer.parseInt(simpleDateformat.format(date));
int numYears = 100;
//
what would be the value for 'step' variable for decrement operation? i mean if i give step='-1' i get error. How do i write the decrement operation?
can someone provide me for loop for the above functionality? Thanks in advance
Costi Ciudatu
Ranch Hand
Joined: Oct 24, 2006
Posts: 74
posted
0
I was not aware that c:forEach has any problem with decrementing, and I'm not really able to test that right now.
But as a simple workaround (in case you won't get the proper solution), you can just have some i counter incremented (the traditional way from 0 to 100, and inside the foreach block use (currentYear - i) for year (so you'll just emulate the decrementation).
san krish
Ranch Hand
Joined: Aug 11, 2010
Posts: 40
posted
0
Thanks for your reply.
But I want to know the validation with decrement operation something like "step=-1". If you have time could you please let me know.
Anyone else, who knows a solution and worked with decrement, please let me know what would be the error.
Your year goes from 100 years ago until now.
For each such year, you're printing the "100 year after" year. Your output probably starts with now and goes 100 years in the future.
Try this:
<%int year = Integer.parseInt(simpleDateformat.format(date));%>
You can't mix scripting variables with the JSTL and EL.
Costi Ciudatu
Ranch Hand
Joined: Oct 24, 2006
Posts: 74
posted
0
You're right... I think I've only used scriptlets once a few years ago...
So, let's assume the ${year} is set as a request attribute...
san krish
Ranch Hand
Joined: Aug 11, 2010
Posts: 40
posted
0
Thanks all for your valuable time and help...
now I have come up with a new question.
I have a JSTL that displays 3 dropdowns,(month/day/year) as follows:
<form:select path="months" items="${amonths}"/>
<form:select path="days" items="${adays}"/>
<form:select path="years" items="${ayears}"/>
months dropdown has values from (1-12), day dropdown from (1-31) year dropdown from (2011-1911)
Now i want to make JS validation such that, if month is selected as '2' for Feb, days dropdown should display values from (1-28) dynamically and so for every month.
Jan should show 1-31 feb 1-28 except leap yr march 1-31 and so on...
How can i achieve this in JS?
san krish
Ranch Hand
Joined: Aug 11, 2010
Posts: 40
posted
0
I do not want to use Ajax though. Is it possible in JS?