2014-03-25 32 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中使用它。