【发布时间】:2015-11-07 08:59:15
【问题描述】:
我正在开发一个 JSF 应用程序。我使用新的 LinkedHashMap 从数据库表中检索两个列值以填充列表框。第一列包含项目,第二列包含价格。这些项目显示在我的列表框中,但是当我选择一个或两个项目并单击按钮计算时,它给了我错误。错误是
javax.faces.FacesException:目标模型类型不是集合或数组
在下面查看我的代码Java:
String url = "jdbc:mysql://localhost:3306/ListBox";
String user = "root";
String pw = "root";
String favlst;
double total;
double price;
String item;
Map<String,Object> lst; {
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, user, pw);
String sql = "SELECT * FROM list";
Statement stt = con.createStatement();
ResultSet rs = stt.executeQuery(sql);
lst = new LinkedHashMap<String, Object>();
while(rs.next()){
price = rs.getDouble("Price");
item = rs.getString("Item");
lst.put(item, price);
}
}catch(Exception e){
}
}
public double getTotal() {
return total;
}
public void setTotal(double total) {
this.total = total;
}
public Map<String, Object> getSelectlst() {
return lst;
}
public String Calculate(){
total = 0;
price = 0;
total += (Double)lst.get(item);
return "success";
}
}
JSF
<h:form>
<h3> Generated by Map </h3>
<h:selectManyListbox value = "#{menu2.selectlst}">
<f:selectItems value = "#{menu2.selectlst}"/>
</h:selectManyListbox>
<br> <br>
<h:commandButton value = "Calculate" action = "#{menu2.Calculate}"/>
<br> <br>
Total: Rs <h:outputLabel value = "#{menu2.total}"></h:outputLabel>
</h:form>
【问题讨论】:
标签: jsf