Click to See Complete Forum and Search --> : dynamicdate of birth drop down
jrthor2
06-23-2005, 08:36 AM
I have a form that ask for your date of birth using 3 dropdown boxes. I want these boxes to get their values from a bean, so that I can use these methods elsewhere in my application. I need the month to to look like this:
<option value="01">January</option>
And I then need the list of days/years. The years should start from sy 1930 up to the current year.
Could someone please help me with creating these methods? I will be using these in a <h:SelectOneMenu> jsf component.
Thanks!!
buntine
06-23-2005, 04:38 PM
You could write three methods.
import com.javaranch.common.JDate;
import java.util.Calendar;
<%
getDays()
{
for (int i=1; i<32; i++)
{
String strLabel = (String)i;
String strValue = strLabel;
%>
<f:selectItem itemLabel="<%=strLabel%>" itemValue="<%=strValue%>" />
<%
}
}
%>
getMonth()
{
for (int i=1; i<32; i++)
{
JDate monthDate = new JDate(2005, i, 1);
String strLabel = monthName.getMonthString();
String strValue = (String)i;
%>
<f:selectItem itemLabel="<%=strLabel%>" itemValue="<%=strValue%>" />
<%
}
}
<%
getDays()
{
Calendar cal = Calendar.getInstance(TimeZone.getDefault());
int year = cal.get(Calendar.YEAR);
for (int i=1930; i<year; i++)
{
String strLabel = (String)i;
String strValue = strLabel;
%>
<f:selectItem itemLabel="<%=strLabel%>" itemValue="<%=strValue%>" />
<%
}
}
%>
Something like that should help out.
Regards.
jrthor2
06-24-2005, 08:07 AM
for the getDays method, I get an error on this line:
String strLabel = (String)i;
That says "cannot cast from int to String.
buntine
06-24-2005, 09:10 AM
Use this instead:
String strLabel = Integer.toString(i);
Regards.
jrthor2
06-27-2005, 07:31 AM
sould I make these methods public void, public String??
buntine
06-27-2005, 08:36 PM
public void getDays()
{
...
}