I’m having a little problem populating a combo box with struts using the action class..
This is my form element:
<s:select label = "Estado"
name = "estados"
value = "#estados"
headerKey = "-1"
headerValue = "---Seleccione---"
list = "estados"/>
And this is action class:
public class PrepararMedicosAction extends ActionSupport
implements Preparable, ParameterAware{
public List <Estado> estados;
private IFachada lookupFachadaRemote() {
try {
Context c = new InitialContext();
return (IFachada) c.lookup("java:global/Fachada/Fachada!com.interfaces.IFachada");
} catch (NamingException ne) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
throw new RuntimeException(ne);
}
}
public String display() {
return NONE;
}
@Override
public void prepare() throws Exception {
this.estados= fachada.getEstados();
}
}
Struts2’s Select attribute:
If
namerefers to aList<String>, you can use thelistattribute to display the strings in both keys and values; if instead, as in your case,namerefers to aList<Object>, you have to specify which attribute is the key and which is the value.Example (let’s translate “Estados” to “States”):
then expose a
List<State> statesthrough agetStates()method,and your preferred state through
getMyPreferredState()method.In the jsp you will write: