0
我有一個名爲Lecturer的託管bean。講師管理bean包含部門之間的關係。我想顯示存儲在數據庫中的所有部門。當我註冊講師時,我需要獲得其部門。當我添加selectOneMenu(主要面孔)時,JSF頁面不起作用
我的講師管理bean。我有適當的setter和getter方法。我只是爲了澄清而忽略它。
public class Lecturer
{
private String name;
private String surname;
private String email;
private String username;
private String password;
private List<Department> departments;
private LecturerService lecturerService;
private DepartmentService departmentService;
}
我Licturer.xhtml文件:
<h:form>
<f:view>
<p:panelGrid columns="2">
<f:facet name="header">Lecturer Registration Form</f:facet>
<h:outputLabel for="name" value="Name :" />
<p:inputText id="name" value="#{Lecturer.name}" label="Name" required="true" />
<h:outputLabel for="surname" value="Surname :" />
<p:inputText id="surname" value="#{Lecturer.surname}" label="Surname" required="true" />
<h:outputLabel for="department" value="Department :" />
<p:selectOneMenu value="#{Lecturer.departments}" effect="fade" editable="true" var="p" >
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{Lecturer.departments}" var="lec"
itemLabel="#{lec.name}" itemValue="#{lec.name}"/>
</p:selectOneMenu>
<h:outputLabel for="email" value="Email :" />
<p:inputText id="email" value="#{Lecturer.email}" label="Email" required="true" />
<h:outputLabel for="username" value="User Name :" />
<p:inputText id="username" value="#{Lecturer.username}" label="Email" required="true" />
<h:outputLabel for="password" value="Password :" />
<p:inputText id="password" value="#{Lecturer.password}" label="Password" required="true" />
<f:facet name="footer">
<p:commandButton type="submit"
id="lecturer"
action="#{Lecturer.registerLecturer}"
value="Register" icon="ui-icon-disk">
</p:commandButton>
</f:facet>
</p:panelGrid>
</f:view>
</h:form>
我faces-config.xml中
<managed-bean>
<managed-bean-name>Lecturer</managed-bean-name>
<managed-bean-class>com.studinfo.controller.Lecturer</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>departmentService</property-name>
<property-class>com.studinfo.services.DepartmentService</property-class>
<value>#{DepartmentService}</value>
</managed-property>
<managed-property>
<property-name>lecturerService</property-name>
<property-class>com.studinfo.services.LecturerService</property-class>
<value>#{LecturerService}</value>
</managed-property>
</managed-bean>
當我刪除selectOneMenu用於標籤。我的頁面正常工作。
有關解決方案的任何想法?
我是否必須在字符串和Department類之間添加轉換器?
@erencan:仔細看看http://www.primefaces.org/showcase/ui/selectOneMenu.jsf(見第二個例子,它是'city'和'cities') – MartinK 2012-04-19 09:57:54
@MartinK是我看過在它。我認爲我的問題是缺少轉換器。我嘗試在我的Department類和String之間添加一個轉換器。 – erencan 2012-04-19 10:01:18
我也想顯示存儲在數據庫中的所有部門。用戶可以選擇其中一個用於新講師註冊。因此,我必須使用頁面上的部門列表。 – erencan 2012-04-19 10:02:31