私はjsf hibernate spring primefacesの統合を使用しています。記録を更新したい。しかし、私のコードは機能しません。挿入と削除はうまく機能します。エラーはありません。正しいコードを書くのを手伝ってください。personeldao.java
public class PersonelDao implements IPersonelDao {
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
public void updatePersonel(Personel personel) {
getSessionFactory().getCurrentSession().update(personel);
}
public void deletePersonel(Personel personel) {
getSessionFactory().getCurrentSession().delete(personel);
}
PersonalService.java
@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=true)
public void updatePersonel(Personel personel){
getPersoneldao().updatePersonel(personel);
}
@Transactional(readOnly=false)
public void deletePersonel(Personel personel) {
getPersoneldao().deletePersonel(personel);
}
PersonalBean.java
@ManagedBean(name="personelMB")
@RequestScoped
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;
//getter and setter
public void deletePersonel(int personel_id){
Personel personel=(Personel)personelservice.getPersonelId(personel_id);
getPersonelservice().deletePersonel(personel);
}
public void updatePersonel(RowEditEvent event){
Personel personel = (Personel)event.getObject();
getPersonelservice().updatePersonel(personel);
//getDataFromDatabase();
}
}
個人.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="pdataTable" var="personel" value="#{personelMB.personelList}" rowKey="#{personelMB.personel_id}" editable="true"
>
<p:ajax event="rowEdit" update="@form" listener="#{personelMB.updatePersonel}"/>
<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="نام">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{personel.pname}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{personel.pname}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="نام خانوادگی">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{personel.pfamily}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{personel.pfamily}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="آدرس">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{personel.paddress}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{personel.paddress}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="تلفن">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{personel.pphone}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{personel.pphone}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="حذف">
<f:facet name="حذف">
<h:outputText value="" />
</f:facet>
<p:commandButton icon="ui-icon-trash" title="حذف"
actionListener="#{personelMB.deletePersonel(personel.personel_id)}" update="@form" ajax="true"/>
</p:column>
<p:column headerText="ويرايش">
<p:rowEditor />
</p:column>
<f:facet name="footer">
تعداد رکورد#{fn:length(personelMB.getPersonelList())} میباشد.
</f:facet>
</p:dataTable>
</h:form>
</h:body>
</html>
個人.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(){
}
public Set<Stufftransfer> getStufftransfers() {
return stufftransfers;
}
public void setStufftransfers(Set<Stufftransfer> stufftransfers) {
this.stufftransfers = stufftransfers;
}
public Personel(int personel_id, String pname, String pfamily, String paddress,
String pphone) {
super();
this.personel_id = personel_id;
this.pname = pname;
this.pfamily = pfamily;
this.paddress = paddress;
this.pphone = pphone;
}
//getter and setter