Hi Simon, Greetings from Canada,it sounds like your book is what I am looking for, and easy to understand.
I have some java code in my jsp page, and actually like it there, but I keep hearing about
"maintainability and reusability, it's best not to place too much Java code in your JSPs."
I haven't seen a posting of code snippets in the book givaways, but the below piece of code is what I have on my page. Is it best to put it into a tag or a bean? I should note that I have a number of these for year month and days, where the years start and end with different dates, and I use javascript for the validation.
<%
String passedBirthDateYear = (String) session.getValue("birthDateYear");
if (passedBirthDateYear==null) passedBirthDateYear="";
int birthStart = 82; // when does the years start
int birthEnd = 16; // and when do they end
String[] birthYears = new String[birthStart-birthEnd+1];
java.util.Calendar birthCal = java.util.Calendar.getInstance();
birthCal.add(java.util.Calendar.YEAR,-birthStart);
//for (int i=0;i<birthStart-birthEnd+1;i++) { //for 1920-1986
for (int i=(birthYears.length-1); i>=0; i--) { //1986-1920
birthYears[i]= String.valueOf(birthCal.get(java.util.Calendar.YEAR));
birthCal.add(java.util.Calendar.YEAR,1);
}
// Here we have an array of years from 2002-16 to 2002-82
// dob year needs to start with 1986 and end with 1920
// next year it would be 2003-17 to 2003-83
%>
---------
down in the form i have the other half
<select name="birthDateYear" tabindex="2" <% if ( secureSite != null ){ %>
class="disable" onFocus="termDtYr.focus()"
<% } else if ( display ){ %> onfocus='messageBirthDate()'<% }else{ %>
<% } %> onChange="return (isBirthDate(this.form, 'check') && allOK(this.form, 'check'));">
<OPTION >Year
<%
String ySelect1 = "";
for (int i=0;i<birthYears.length;i++) {
if (birthYears[i].equals(passedBirthDateYear)) ySelect1 = "selected";
else ySelect1 = "";
%>
<option value="<%= birthYears[i] %>"<%= ySelect1 %>><%= birthYears[i] %></option>
<%}%></select>
so what do you think?