0
我正在使用JSF應用程序。我已經使用新的LinkedHashMap從數據庫表中檢索兩個列值來填充列表框。第一列包含項目,第二列包含價格。這些項目顯示在我的列表框中,但是當我選擇一個或兩個項目並單擊按鈕計算時,它會給我提供錯誤。該錯誤是使用LinkedHashMap在h中添加所選項目:selectManyListbox
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>
請更正我的代碼:( –
所有的信息都在那裏,如果你想要一個充分準備的例子,等待有更多時間的人和一臺真正的電腦,我沒有時間,也沒有渴望和材料一個手機)進一步幫助,對不起 – Kukeltje
順便說一句,標題是不符合問題。由於項目**顯示,因此mysql標記是'錯誤'(如java標籤) – Kukeltje