我在我的项目中使用 jsf hibernate spring primfaces 的集成。我想删除我的 primefaces 数据表中的行。但我不确定我的托管 bean 中的删除方法。当我想删除我有以下错误。请帮我编写正确的 deletePersonel 方法。
/personel.xhtml @95,74 actionListener="#{personelMB.deletePersonel()}": java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
个人资料.java
@Entity
@Table(name="TBLPERSONEL")
public class Personel {
@Id
@Column(name="PERSONEL_ID")
private int personel_id;
@Column(name="PNAME")
private String pname;
@Column(name="PFAMILY")
private String pfamily;
@Column(name="PADDRESS")
private String paddress;
@Column(name="PPHONE")
private String pphone;
@OneToOne
@PrimaryKeyJoinColumn
private Manager manager;
@OneToMany(mappedBy="personel")
private Set<Stufftransfer> stufftransfers;
public Personel(){
}
//getter and setter
个人道
public class PersonelDao implements IPersonelDao {
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public void deletePersonel(Personel personel) {
getSessionFactory().getCurrentSession().delete(personel);
}
人事服务
@Transactional(readOnly=true)
public class PersonelService implements IPersonelService{
IPersonelDao personeldao;
public IPersonelDao getPersoneldao() {
return personeldao;
}
public void setPersoneldao(IPersonelDao personeldao) {
this.personeldao = personeldao;
}
@Transactional(readOnly=false)
@Override
public void deletePersonel(Personel personel) {
getPersoneldao().deletePersonel(personel);
}
个人豆
@ManagedBean(name="personelMB")
@SessionScoped
public class PersonelBean implements Serializable{
private static final long serialVersionUID = 1L;
@ManagedProperty(value="#{PersonelService}")
IPersonelService personelservice;
List<Personel> personelList;
private int personel_id;
private String pname;
private String pfamily;
private String paddress;
private String pphone;
public IPersonelService getPersonelservice() {
return personelservice;
}
public void setPersonelservice(IPersonelService personelservice) {
this.personelservice = personelservice;
}
public List<Personel> getPersonelList() {
personelList=new ArrayList<Personel>();
personelList.addAll(getPersonelservice().getPersonels());
return personelList;
}
public void setPersonelList(List<Personel> personelList) {
this.personelList = personelList;
}
public void addPersonel(){
Personel personel=new Personel();
personel.setPaddress(getPaddress());
personel.setPersonel_id(getPersonel_id());
personel.setPfamily(getPfamily());
personel.setPname(getPname());
personel.setPphone(getPphone());
getPersonelservice().addPersonel(personel);
}
public void deletePersonel(){
Personel personel=(Personel)personelservice.getPersonelId(personel_id);
getPersonelservice().deletePersonel(personel);
}
//getter and setter
个人资料.xhtml
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="rtl"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
>
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>اطلاعات پرسنلی</title>
</h:head>
<h:body>
<h1>اضافه کردن پرسنل جدید</h1>
<h:form>
<h:panelGrid columns="4" >
شماره پرسنلی :
<h:inputText id="id" value="#{personelMB.personel_id}"
size="20" required="true"
label="id" >
</h:inputText>
<br></br>
نام :
<h:inputText id="name" value="#{personelMB.pname}"
size="20" required="true"
label="Name" >
</h:inputText>
نام خانوادگی:
<h:inputText id="family" value="#{personelMB.pfamily}"
size="20" required="true"
label="family" >
</h:inputText>
آدرس :
<h:inputTextarea id="address" value="#{personelMB.paddress}"
cols="30" rows="10" required="true"
label="Address" >
</h:inputTextarea>
تلفن:
<h:inputText id="tel" value="#{personelMB.pphone}"
size="20" required="true"
label="tel" >
</h:inputText>
</h:panelGrid>
<h:commandButton value="درج اطلاعات" action="#{personelMB.addPersonel()}" />
</h:form>
<h2>مشاهده اطلاعات پرسنل</h2>
<h:form prependId="false">
<p:dataTable id="dataTable" var="personel" value="#{personelMB.personelList}" rowKey="#{personelMB.personel_id}">
<f:facet name="header">
اطلاعات پرسنل
</f:facet>
<p:column>
<f:facet name="header">
شماره پرسنلی
</f:facet>
<h:outputText value="#{personel.personel_id}" />
<f:facet name="footer">
کدملی
</f:facet>
</p:column>
<p:column headerText="نام">
<h:outputText value="#{personel.pname}" />
</p:column>
<p:column headerText="نام خانوادگی">
<h:outputText value="#{personel.pfamily}" />
</p:column>
<p:column headerText="آدرس">
<h:outputText value="#{personel.paddress}" />
</p:column>
<p:column headerText="تلفن">
<h:outputText value="#{personel.pphone}" />
</p:column>
<p:column>
<f:facet name="حذف">
<h:outputText value="" />
</f:facet>
<p:commandButton icon="ui-icon-close" title="حذف"
actionListener="#{personelMB.deletePersonel()}" />
</p:column>
<f:facet name="footer">
تعداد رکورد#{fn:length(personelMB.getPersonelList())} میباشد.
</f:facet>
</p:dataTable>
</h:form>
</h:body>
</html>
请帮助我在我的 PersonelBean.java 中编写正确的 deletePersonel。