• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

struts html:options collection

 
Abebe Belew
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to poptulate a drop down list by using html ption but I get this error message when I try to run the app. "Cannot find bean under name glu_bp' " any idea why?

jsp tag:
=======
<html:select name="glucoseForm" property="glucose_bloodPressure">
<html ptions collection="glu_bp" property="id" labelProperty="description"/>
</html:select>

Action
======
HttpSession session = request.getSession(true);
GlucoseForm glucoseForm = (GlucoseForm) form;

GluService service = new GluService();
Collection glu_bp = service.getGlu_bp();
session.setAttribute("glu_bp", glu_bp);
glucoseForm.setGlucose_bloodPressure("Glucose"); //to set the default value

beans
=========
Glucose_bloodPressureBean.java

public class Glucose_bloodPressureBean {

private int id;
private String description;

public Glucose_bloodPressureBean() {
}
public Glucose_bloodPressureBean( int id, String description ) {
this.id = id;
this.description = description;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}


GluService.java

import java.util.Collection;
import java.util.ArrayList;

public class GluService {

public Collection getGlu_bp() {
//call business layer to return Collection of Department beans
//since we aren't dealing with the model layer, we'll mimic it here
ArrayList list = new ArrayList(2);
list.add( new Glucose_bloodPressureBean( 0, "Glucose"));
list.add( new Glucose_bloodPressureBean( 1, "Blood Pressure"));

System.out.println(" this is the array list" + list);
return list;
}


}
 
Junilu Lacar
Bartender
Pie
Posts: 7750
61
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What URL are you trying to bring up? You'll get the message if you try to go directly to the JSP without going through the Action first.
 
John Smith
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need a bean efine on the collection bean, be sure to include it's type or your options property fields will not find the getter methods
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic