Jpa RichFaces 4数据表编辑问题
我想做这样的表格编辑像这里->。问题是,当我在editPane(popupPanel)中进行更改时,它们在私有的OsobaTelefon edytujOsobe中不会被记住。这使得无法通过JPA进行更新。我有所有的getter和setter,类OsobaTelefon实现是可序列化的Jpa RichFaces 4数据表编辑问题,jpa,richfaces,popuppanel,Jpa,Richfaces,Popuppanel,我想做这样的表格编辑像这里->。问题是,当我在editPane(popupPanel)中进行更改时,它们在私有的OsobaTelefon edytujOsobe中不会被记住。这使得无法通过JPA进行更新。我有所有的getter和setter,类OsobaTelefon实现是可序列化的 @ManagedBean(name = "administrator") @ViewScoped @SessionScoped public class Administrator implements Seria
@ManagedBean(name = "administrator")
@ViewScoped
@SessionScoped
public class Administrator implements Serializable
@EJB
private UzytkownikFacade uzytkownikFacade;
private static final long serialVersionUID = 1L;
@EJB
private OsobaFacade osobaFacade;
private Osoba osobaAdmina;
private int numerStrony = 1;
private Uzytkownik uzytkownik;
private List<Osoba> listaOsob;
private static final int CLIENT_ROWS_IN_AJAX_MODE = 10;
private int clientRows;
private int wybranaOsoba;
private OsobaTelefon edytujOsobe; //it doesn't remember the changes made in editPane
private List<OsobaTelefon> osobyITelefony;
/**
* Creates a new instance of Administrator
*/
public Administrator() {
}
public void aktualizacjaWybranejOsoby() {
this.osobyITelefony.set(this.wybranaOsoba, this.edytujOsobe);
Osoba nowaOsoba = new Osoba();
List<Telefon> nowaListaTelefonow = new ArrayList<Telefon>();
OsobaTelefon osobaTelefon = this.osobyITelefony.get(this.wybranaOsoba);
int o = this.osobyITelefony.get(this.wybranaOsoba).getIdosoby();
int of = this.osobyITelefony.get(this.wybranaOsoba).getIdtelefonu();
System.out.println("Wybrana osoba ID " + o);
System.out.println("Wybrane ID fona " + of);
boolean znalezionoOsobe = false;
Iterator<Osoba> iteOs = this.listaOsob.iterator();
while (!znalezionoOsobe && iteOs.hasNext()) {
Osoba os = iteOs.next();
if (os.getIdosoba() == o) {
znalezionoOsobe = true;
nowaOsoba.setIdosoba(os.getIdosoba());
nowaOsoba.setImie(osobaTelefon.getImie());
nowaOsoba.setNazwisko(osobaTelefon.getNazwisko());
nowaOsoba.setKodpocztowy(osobaTelefon.getKodpocztowy());
nowaOsoba.setMiejscowosc(osobaTelefon.getMiejscowosc());
nowaOsoba.setUlica(osobaTelefon.getUlica());
nowaOsoba.setUzytkownikList(os.getUzytkownikList());
Telefon nowyTelefon = new Telefon();
for (Telefon tel : os.getTelefonList()) {
if (tel.getIdtelefon() == of) {
nowyTelefon.setFkIdosoba(nowaOsoba);
nowyTelefon.setIdtelefon(of);
nowyTelefon.setNumer(this.edytujOsobe.getNumer());
System.out.println("Nr tel. "+tel.getNumer());
nowyTelefon.setOpis(this.edytujOsobe.getOpis());
nowyTelefon.setZastrzezony(this.edytujOsobe.getZastrzezony());
nowaListaTelefonow.add(nowyTelefon);
} else {
nowaListaTelefonow.add(tel);
}
}
nowaOsoba.setTelefonList(nowaListaTelefonow);
this.osobaFacade.aktualizujOsoba(nowaOsoba);
this.pobierzOsobyDoTabeli();
}
}
}
public List<Osoba> pobierzOsobyDoTabeli() {
//getting people with phone to List<OsobaTelefon> works good
}
public void switchAjaxLoading(ValueChangeEvent event) {
this.clientRows = (Boolean) event.getNewValue() ? CLIENT_ROWS_IN_AJAX_MODE : 0;
}
public void zapelnijListeTelefonow() {
//getting people phone number to List<Phone> works good
}
public void usunOsobe() {
//deleting people works good
}
}
@ManagedBean(name=“administrator”)
@视域
@会议范围
公共类管理员实现可序列化
@EJB
私人Uzytkownike门面Uzytkownike门面;
私有静态最终长serialVersionUID=1L;
@EJB
私人Osobaafacade Osobaafacade;
私人奥索巴·奥索巴德米纳;
私有整数=1;
乌兹特科夫尼克私人酒店;
私有列表列表;
私有静态final int CLIENT_ROWS_在_AJAX_模式下=10;
私有int客户端行;
怀布拉纳奥索巴私人酒店;
私人奥索巴泰勒丰·埃迪图约索贝//它不记得在editPane中所做的更改
私人名单osobyITelefony;
/**
*创建管理员的新实例
*/
公共行政人员(){
}
公共无效aktualizacjaWybranejOsoby(){
this.osobyITelefony.set(this.wybranaOsoba,this.edytujOsobe);
Osoba nowaOsoba=新的Osoba();
List nowalistatelefow=new ArrayList();
OsobaTelefon OsobaTelefon=this.osobyITelefony.get(this.wybranaOsoba);
int o=this.osobyITelefony.get(this.wybranaOsoba.getIdosoby();
int of=this.osobyITelefony.get(this.wybranaOsoba.getIdtelefonu();
系统输出打印LN(“Wybrana osoba ID”+o);
系统输出打印号(“Wybrane ID fona”+of);
布尔值znalezionoOsobe=false;
迭代器iteOs=this.listaosab.Iterator();
而(!znalezionoOsobe&&iteOs.hasNext()){
Osoba os=iteOs.next();
if(os.getIdosoba()==o){
znalezionoOsobe=true;
nowaOsoba.setIdosoba(os.getIdosoba());
nowaOsoba.setImie(osobaTelefon.getImie());
nowaOsoba.setNazwisko(osobaTelefon.getNazwisko());
nowaOsoba.setKodpocztowy(osobaTelefon.getKodpocztowy());
nowaOsoba.setMiejscowosc(osobaTelefon.getMiejscowosc());
nowaOsoba.setUlica(osobaTelefon.getUlica());
nowaOsoba.setUzytkownikList(os.getUzytkownikList());
Telefon nowyTelefon=新Telefon();
for(Telefon电话:os.getTelefonList()){
如果(电话:getIdtelefon()==of){
nowyTelefon.setFkIdosoba(nowaOsoba);
nowyTelefon.setIdtelefon(of);
nowyTelefon.setNumer(this.edytujOsobe.getNumer());
System.out.println(“Nr tel.”+tel.getNumer());
nowyTelefon.setOpis(this.edytujOsobe.getOpis());
nowyTelefon.setZastrzezony(this.edytujOsobe.getZastrzezony());
添加(nowyTelefon);
}否则{
nowaListaTelefonow.add(电话);
}
}
nowaOsoba.setTelefonList(nowalistatelefow);
这个.osobaafacade.aktualizujOsoba(nowaOsoba);
this.pobierzOsobyDoTabeli();
}
}
}
公共列表pobierzOsobyDoTabeli(){
//让有电话的人列出清单效果很好
}
公共无效开关AJAX加载(ValueChangeEvent事件){
this.clientRows=(布尔)event.getNewValue()?客户端\u行\u在\u AJAX\u模式下:0;
}
公共无效Zapelnijlistelefonow(){
//让人们的电话号码列出来效果很好
}
公共无效的usunOsobe(){
//删除人很有效
}
}
XHTML
<a4j:status onstart="#{rich:component('statPane')}.show()" onstop="#{rich:component('statPane')}.hide()" />
<h:form id="formProjekty">
<rich:dataTable value="#{administrator.osobyITelefony}"
var="pr"
iterationStatusVar="ite"
id="table"
rows="8" >
<rich:column width="auto">
<f:facet name="header">Imię</f:facet>
<h:outputText value="#{pr.imie}" />
</rich:column>
<rich:column>
<a4j:commandLink styleClass="no-decor"
render="editGrid"
execute="@this"
oncomplete="#{rich:component('editPane')}.show()">
<h:graphicImage library="img" name="edit.gif" alt="Edycja"/>
<a4j:param value="#{ite.index}"
assignTo="#{administrator.wybranaOsoba}" />
<f:setPropertyActionListener target="#{administrator.edytujOsobe}"
value="#{pr}" />
</a4j:commandLink>
<a4j:commandLink styleClass="no-decor"
execute="@this"
render="@none"
oncomplete="#{rich:component('confirmPane')}.show()">
<h:graphicImage library="img" name="delete.gif" alt="Usuń"/>
<a4j:param value="#{ite.index}"
assignTo="#{administrator.wybranaOsoba}" />
<f:setPropertyActionListener target="#{administrator.edytujOsobe}"
value="#{pr}" />
</a4j:commandLink>
</rich:column>
<f:facet name="footer">
<rich:dataScroller page="#{administrator.numerStrony}" />
</f:facet>
</rich:dataTable>
<a4j:jsFunction name="remove"
action="#{administrator.usunOsobe()}"
render="table"
execute="@this"
oncomplete="#{rich:component('confirmPane')}.hide();" />
<a4j:jsFunction name="edycja"
action="#{administrator.aktualizacjaWybranejOsoby()}"
render="table"
execute="@this"
oncomplete="#{rich:component('editPane')}.hide();" />
<rich:popupPanel id="statPane" autosized="true">
<h:graphicImage library="img" name="ai.gif" alt="Czekaj"/>
Proszę czekać...
</rich:popupPanel>
<rich:popupPanel id="confirmPane" autosized="true">
Czy na pewno usunać?
<a4j:commandButton value="Tak" onclick="remove();
return false;" />
<a4j:commandButton value="Nie"
onclick="#{rich:component('confirmPane')}.hide();
return false;" />
</rich:popupPanel>
<rich:popupPanel header="Edycja Osoby"
id="editPane"
domElementAttachment="parent" width="180" height="420">
<h:panelGrid columns="1" id="editGrid">
<h:panelGroup >
<h:outputText value="Imię" /><br />
<h:inputText value="#{administrator.edytujOsobe.imie}" >
<f:validateLength maximum="32" minimum="3"/>
</h:inputText>
</h:panelGroup>
</h:panelGrid><br/>
<a4j:commandButton value="Aktualizuj"
onclick="edycja(); return false;"/>
<a4j:commandButton value="Anuluj"
onclick="#{rich:component('editPane')}.hide();
return false;" />
</rich:popupPanel>
</h:form>
伊米ę
Proszęczekać。。。
Czy na pewno usunać?
如果您可以更改它,那么让Aktualizuj a4j链接更容易一点。试试看:
<a4j:commandButton value="Aktualizuj"
onclick="#{rich:component('editPane')}.hide();"
action="#{administrator.aktualizacjaWybranejOsoby()}" render="table"/>
<rich:popupPanel header="Edycja Osoby"
id="editPane"
domElementAttachment="parent" width="180" height="420">
<a4j:region>
<h:panelGrid columns="1" id="editGrid">
<h:panelGroup >
<h:outputText value="Imię" /><br />
<h:inputText value="#{administrator.edytujOsobe.imie}" >
<f:validateLength maximum="32" minimum="3"/>
</h:inputText>
</h:panelGroup>
</h:panelGrid><br/>
<a4j:commandButtonvalue="Aktualizuj" onclick="# {rich:component('editPane')}.hide();"action="#{administrator.aktualizacjaWybranejOsoby()}" render="table"/>
<a4j:commandButton value="Anuluj"
onclick="#{rich:component('editPane')}.hide();
return false;" />
</a4j:region>
</rich:popupPanel>
并在inputText和链接上放置一个a4j:区域,以仅发送所需的值:
<a4j:commandButton value="Aktualizuj"
onclick="#{rich:component('editPane')}.hide();"
action="#{administrator.aktualizacjaWybranejOsoby()}" render="table"/>
<rich:popupPanel header="Edycja Osoby"
id="editPane"
domElementAttachment="parent" width="180" height="420">
<a4j:region>
<h:panelGrid columns="1" id="editGrid">
<h:panelGroup >
<h:outputText value="Imię" /><br />
<h:inputText value="#{administrator.edytujOsobe.imie}" >
<f:validateLength maximum="32" minimum="3"/>
</h:inputText>
</h:panelGroup>
</h:panelGrid><br/>
<a4j:commandButtonvalue="Aktualizuj" onclick="# {rich:component('editPane')}.hide();"action="#{administrator.aktualizacjaWybranejOsoby()}" render="table"/>
<a4j:commandButton value="Anuluj"
onclick="#{rich:component('editPane')}.hide();
return false;" />
</a4j:region>
</rich:popupPanel>
我还将render=“table”添加到Aktualizuj a4j:链接以更新数据表中的值