jrthor2
06-28-2005, 08:20 AM
I have a form that gets a dropdown box with a list of states from a bean. On my profile update screen, how can I get the current state they selected as the state that is selected in my dropdown box? Here is the code for the bean that just lists the states:
public class StateList {
public StateList(){
//empty constructure
}
private SelectItem[] stateList = {
new SelectItem ("",""),
new SelectItem ("AL","Alabama"),
new SelectItem ("AK","Alaska"),
new SelectItem ("AZ","Arizona"),
new SelectItem ("AR","Arkansas"),
new SelectItem ("CA","California"),
new SelectItem ("CO","Colorado"),
new SelectItem ("CT","Connecticut"),
new SelectItem ("DE","Delaware"),
new SelectItem ("DC","District of Columbia"),
new SelectItem ("FL","Florida"),
new SelectItem ("GA","Georgia"),
new SelectItem ("HI","Hawaii"),
new SelectItem ("ID","Idaho"),
new SelectItem ("IL","Illinois"),
new SelectItem ("IN","Indiana"),
new SelectItem ("IA","Iowa"),
new SelectItem ("KS","Kansas"),
new SelectItem ("KY","Kentucky"),
new SelectItem ("LA","Louisiana"),
new SelectItem ("ME","Main"),
new SelectItem ("MD","Maryland"),
new SelectItem ("MA","Massachusetts"),
new SelectItem ("MI","Michigan"),
new SelectItem ("MN","Minnesota"),
new SelectItem ("MO","Missouri"),
new SelectItem ("MT","Montana"),
new SelectItem ("NE","Nebraska"),
new SelectItem ("NV","Nevada"),
new SelectItem ("NH","New Hampshire"),
new SelectItem ("NJ","New Jersey"),
new SelectItem ("NM","New Mexico"),
new SelectItem ("NY","New York"),
new SelectItem ("NC","North Carolina"),
new SelectItem ("ND","North Dakota"),
new SelectItem ("OH","Ohio"),
new SelectItem ("OK","Oklahoma"),
new SelectItem ("OR","Oregon"),
new SelectItem ("PA","Pennsylvania"),
new SelectItem ("RI","Rhode Island"),
new SelectItem ("SC","South Carolina"),
new SelectItem ("TN","Tennessee"),
new SelectItem ("TX","Texas"),
new SelectItem ("UT","Utah"),
new SelectItem ("VT","Vermont"),
new SelectItem ("VA","Virginia"),
new SelectItem ("WV","West Virginia"),
new SelectItem ("WI","Wisconsin"),
new SelectItem ("WY","Wyoming"),
};
/**
* @return Returns list of states in the United States
*/
public SelectItem[] getStates() {
return stateList;
}
}
And here is the code on my jsf page to get these values:
<h:selectOneMenu id="mnuState">
<f:selectItems value="#{StatesList.states}"/>
</h:selectOneMenu>
Thanks!!!
public class StateList {
public StateList(){
//empty constructure
}
private SelectItem[] stateList = {
new SelectItem ("",""),
new SelectItem ("AL","Alabama"),
new SelectItem ("AK","Alaska"),
new SelectItem ("AZ","Arizona"),
new SelectItem ("AR","Arkansas"),
new SelectItem ("CA","California"),
new SelectItem ("CO","Colorado"),
new SelectItem ("CT","Connecticut"),
new SelectItem ("DE","Delaware"),
new SelectItem ("DC","District of Columbia"),
new SelectItem ("FL","Florida"),
new SelectItem ("GA","Georgia"),
new SelectItem ("HI","Hawaii"),
new SelectItem ("ID","Idaho"),
new SelectItem ("IL","Illinois"),
new SelectItem ("IN","Indiana"),
new SelectItem ("IA","Iowa"),
new SelectItem ("KS","Kansas"),
new SelectItem ("KY","Kentucky"),
new SelectItem ("LA","Louisiana"),
new SelectItem ("ME","Main"),
new SelectItem ("MD","Maryland"),
new SelectItem ("MA","Massachusetts"),
new SelectItem ("MI","Michigan"),
new SelectItem ("MN","Minnesota"),
new SelectItem ("MO","Missouri"),
new SelectItem ("MT","Montana"),
new SelectItem ("NE","Nebraska"),
new SelectItem ("NV","Nevada"),
new SelectItem ("NH","New Hampshire"),
new SelectItem ("NJ","New Jersey"),
new SelectItem ("NM","New Mexico"),
new SelectItem ("NY","New York"),
new SelectItem ("NC","North Carolina"),
new SelectItem ("ND","North Dakota"),
new SelectItem ("OH","Ohio"),
new SelectItem ("OK","Oklahoma"),
new SelectItem ("OR","Oregon"),
new SelectItem ("PA","Pennsylvania"),
new SelectItem ("RI","Rhode Island"),
new SelectItem ("SC","South Carolina"),
new SelectItem ("TN","Tennessee"),
new SelectItem ("TX","Texas"),
new SelectItem ("UT","Utah"),
new SelectItem ("VT","Vermont"),
new SelectItem ("VA","Virginia"),
new SelectItem ("WV","West Virginia"),
new SelectItem ("WI","Wisconsin"),
new SelectItem ("WY","Wyoming"),
};
/**
* @return Returns list of states in the United States
*/
public SelectItem[] getStates() {
return stateList;
}
}
And here is the code on my jsf page to get these values:
<h:selectOneMenu id="mnuState">
<f:selectItems value="#{StatesList.states}"/>
</h:selectOneMenu>
Thanks!!!