我有两个bean 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 :(得分:0)
您的问题是drDetailsbeanList
的类型。 List<DoctorDetailsBean>
不正确。创建返回List<SelectItem>
并在xhtml中使用它的方法。