2014-03-25 51 views
0

我有兩個豆DoctorDetailsBean,PatientDetailsBean填充組合框的值,要填充所有醫生的名字組合框在patientRegistration.xhtml無法從數據庫

 <h:selectOneMenu value="#{patientDetailsBean.refDr}" style="font-size: medium" > 
     <f:selectItems value="#{patientDetailsBean.drDetailsbeanList}" var="dr"  itemLabel="#{dr.doctorName}" itemValue="#{dr.doctorId}" /> 
    </h:selectOneMenu> 

DoctorDetailsBean:

 @ManagedBean(name="doctorBean") 
     @SessionScoped 
     public class DoctorDetailsBean { 
     private Long doctorId; 
     private String doctorName; 
     private String place; 
     private Long phoneNumber; 
     //setters&getters 
     } 

PatientdetailsBean :

 @ ManagedBean(name= "patientDetailsBean") 
     @SessionScoped 
     public class PatientDetailsBean implements Serializable { 
     private Long patientId; 
     private String patientName; 
     private long refDr; 

@ManagedProperty (value ="#{doctorBean}") 
private DoctorDetailsBean doctorDetailsBean; 
private List<Doctor> drList; 
private List<DoctorDetailsBean> drDetailsbeanList; 
private PatientDAO patientDAO; 
private DoctorDAO doctorDAO; 
    //setters&getters 
    public PatientDetailsBean() { 
    } 
    @PostConstruct 
public void init() throws AppException,AppSysException{ 
    drList = new ArrayList<Doctor>(); 
    drList = doctorDAO.getAllDoctors(); 
    drDetailsbeanList = new ArrayList<DoctorDetailsBean>(); 
      for (Doctor doctor : drList) { 
      DoctorDetailsBean doctorDetailsBean = new DoctorDetailsBean(); 
      doctorDetailsBean.setDoctorId(doctor.getDoctorId()); 
      doctorDetailsBean.setDoctorName(doctor.getDoctorName()); 
      doctorDetailsBean.setPlace(doctor.getPlace()); 
      doctorDetailsBean.setPhoneNumber(doctor.getPhoneNumber()); 
      drDetailsbeanList.add(doctorDetailsBean); 
         }   } 

如何解決我的問題

+0

這是什麼問題?你不知道如何顯示你的drDetailsbeanList作爲selectOneMenu? – Mark

回答

0

你的問題是類型drDetailsbeanListList<DoctorDetailsBean>是不正確的。創建方法返回List<SelectItem>並在xhtml中使用它。