File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes struts  html:options collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts  html:options collection" Watch "struts  html:options collection" New topic
Author

struts html:options collection

Abebe Belew
Greenhorn

Joined: Jul 21, 2004
Posts: 19
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

Joined: Feb 26, 2001
Posts: 4699
    
    7

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.


Junilu - [How to Ask Questions] [How to Answer Questions]
John Smith
Ranch Hand

Joined: Sep 02, 2004
Posts: 61
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts html:options collection