1
我目前正在嘗試通過表中的症狀並將它們顯示在selectManyListbox中,儘管當我編譯和運行時列表框並未出現。填充selectManyListbox與數據庫中的項目
的index.html說sym.symptomList和sym.Symptom是未知屬性
的index.html
<h:selectManyListbox id ="list1" value="#{sym.symptomList}">
<f:selectItems value="#{sym.Symptom}" var="c"
itemLabel="#{c.symptomName}" itemValue="#{c.symptomId}"/>
</h:selectManyListbox>
豆:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.util.*;
import java.sql.*;
@ManagedBean(name="sym")
@SessionScoped
public class SymptomBean{
Connection con;
Statement ps;
ResultSet rs;
private List symptomList = new ArrayList();
public List getAllSym() {
int i = 0;
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(...) //ommitted details
ps = con.createStatement();
rs = ps.executeQuery("select * from symptoms");
while (rs.next()) {
symptomList.add(i, new Symptom(rs.getString(1), rs.getString(2)));
i++;
}
}
catch (Exception e)
{
System.out.println("Error Data : " + e.getMessage());
}
return symptomList;
}
public class Symptom{
public String symptomId;
public String symptomName;
public Symptom(String symptomId, String symptomName){
this.symptomId = symptomId;
this.symptomName = symptomName;
}
public String getSymptomId(){
return symptomId;
}
public String getSymptomName(){
return symptomName;
}
}
}
它現在,謝謝! – Infinity 2012-03-08 15:50:42