我插入后的数据表,并且有一个空白字段不显示实体,因为我无法发布图像这里是 url
这是我的实体
@ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "c_kodegl", referencedColumnName = "c_glkode", insertable = false, updatable = false) private Glaccms0 glaccms0;
我正在使用 netbean 7.3、glassfishserver 3.1.2 和 primefaces 3.5
有什么帮助吗?这是我的方法保存
public List<Ksrekening> create() {
System.out.println("masuk create");
HttpSession session;
FacesContext context = FacesContext.getCurrentInstance();
session = (HttpSession) context.getExternalContext().getSession(true);
String servernamesku = (String) session.getAttribute("servernameuserdb");
String username = (String) session.getAttribute("username");
String ipaddress = (String) session.getAttribute("ipaddress");
EntityManager emku = getEntityManager();
Date ddate = new Date();
try {
EntityTransaction trx = em.getTransaction();
trx.begin();
Ksrekening simpanKsrekening = new Ksrekening();
simpanKsrekening.setCDstatus(cdstatuscreate);
simpanKsrekening.setCKodecur(getSelected().getMscurrency0().getCKodecur());
simpanKsrekening.setCKodegl(getSelected().getGlaccms0().getCGlkode());
simpanKsrekening.setCRekening(crekeningcreate);
simpanKsrekening.setCStat(cstatcreate);
simpanKsrekening.setCTipe(ctipecreate);
simpanKsrekening.setDtUser01(ddate);
simpanKsrekening.setDtUser02(ddate);
simpanKsrekening.setNLimit(nlimitcreate);
simpanKsrekening.setVcKeterangan(vcketerangancreate);
simpanKsrekening.setVcStation01(ipaddress);
simpanKsrekening.setVcStation02(ipaddress);
simpanKsrekening.setVcUser01(username);
simpanKsrekening.setVcUser02(username);
em.persist(simpanKsrekening);
trx.commit();
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Proses Insert", "Berhasil"));
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("Master Rekening Berhasil di simpan !"));
current = new Ksrekening();
TypedQuery<Ksrekening> query =
em.createNamedQuery("Ksrekening.findAll", Ksrekening.class);
List<Ksrekening> results = query.getResultList();
return results;
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Proses Insert", "Gagal"));
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("Master Rekening Gagal di simpan"));
return null;
}
}
方法检索表上的数据
public List<Ksrekening> getKsRekeningList() {
TypedQuery<Ksrekening> query =
em.createNamedQuery("Ksrekening.findAll", Ksrekening.class);
List<Ksrekening> results = query.getResultList();
return results;
}
public void setKsRekeningList(List<Ksrekening> ksRekeningList) {
this.ksRekeningList = ksRekeningList;
}
这是我的数据表 xhtml
<h:form id="form">
<p:dataTable id="ListKsRekening"
value="#{MasterRekening.ksRekeningList}"
rowKey="#{item.CRekening}"
selection="#{MasterRekening.selectedKsrekening}"
selectionMode="single"
rows="25"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
paginator="true"
var="item" widgetVar="itemTable"
emptyMessage="Tidak Ada Rekening dengan Kriteria tersebut"
filteredValue="#{MasterRekening.filteredKsrekeningList}">
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search all fields:" />
<p:inputText id="globalFilter" onkeyup="itemTable.filter();" style="width:150px" />
</p:outputPanel>
</f:facet>
<p:column id="kolomRekening" filterBy="#{item.CRekening}"
headerText="Rekening" footerText="Kode Rekening"
filterMatchMode="contains" >
<h:outputText value="#{item.CRekening}"/>
</p:column>
<p:column id="kolomKeterangan" filterBy="#{item.vcKeterangan}"
headerText="Keterangan" footerText="keterangan Rekening"
filterMatchMode="contains" >
<h:outputText value="#{item.vcKeterangan}"/>
</p:column>
<p:column id="kolomCKodegl" filterBy="#{item.CKodegl}"
headerText="Kode Gl" footerText="Kode GL"
filterMatchMode="contains" >
<h:outputText value="#{item.CKodegl}"/>
</p:column>
<p:column id="kolomketeranganckodegl" filterBy="#{item.glaccms0.vcGlket}"
headerText="Keterangan Gl" footerText="Keterangan GL"
filterMatchMode="contains" >
<h:outputText value="#{item.glaccms0.vcGlket}"/>
</p:column>
<p:column id="kolomtipe" filterBy="#{item.CTipe}"
headerText="Tipe" footerText="Tipe"
filterMatchMode="contains" >
<h:outputText value="#{item.CTipeTampil}"/>
</p:column>
<p:column id="kolomcurrency" filterBy="#{item.CKodecur}"
headerText="Currency" footerText="Kode Currency"
filterMatchMode="contains" >
<h:outputText value="#{item.CKodecur}"/>
</p:column>
<p:column id="kolomlimit" filterBy="#{item.NLimit}"
headerText="Limit" footerText="Limit"
filterMatchMode="contains" >
<h:outputText value="#{item.NLimit}"/>
</p:column>
<p:column id="kolomstatus" filterBy="#{item.CStat}"
headerText="Status" footerText="Status"
filterMatchMode="contains" >
<h:outputText value="#{item.CStatTampil}"/>
</p:column>
<p:column id="kolomjurnal" filterBy="#{item.CDstatusTampil}"
headerText="Masuk jurnal" footerText="Jurnal"
filterMatchMode="contains" >
<h:outputText value="#{item.CDstatusTampil}"/>
</p:column>
<f:facet name="footer">
<p:commandButton id="viewButtons" value="Edit" icon="ui-icon-pencil"
update=":displayedit :form:ListKsRekening" oncomplete="carDialogedit.show()"
action="#{MasterRekening.parsing(MasterRekening.selectedKsrekening)}" />
<p:commandButton id="deleteButtons" value="Delete" icon="ui-icon-trash"
update=":displaysdelete :form:ListKsRekening" oncomplete="carDialogsdelete.show()"
action="#{MasterRekening.parsing(MasterRekening.selectedKsrekening)}" />
<p:commandButton id="viewButton" value="View" icon="ui-icon-search"
update=":displayview" oncomplete="carDialogview.show()"/>
<p:commandButton id="createButtons" value="Create" icon="ui-icon-disk"
update=":displaycreate :form:ListKsRekening" oncomplete="carDialogscreate.show()"/>
</f:facet>
</p:dataTable>
</h:form>
这是我的创建对话框
<h:panelGrid id="displaycreate" >
<p:dialog id="dialogscreate" header="Create Rekening" widgetVar="carDialogscreate" resizable="true"
showEffect="clip" hideEffect="fold" >
<h:form id="dlgFormcreate">
<table>
<tr>
<td><h:outputLabel value="Kode Rekening" for="CRekening" /></td>
<td>: <h:inputText id="CRekening" value="#{MasterRekening.crekeningcreate}" /></td>
</tr>
<tr>
<td><h:outputLabel value="Keterangan" for="vcKeterangan" /></td>
<td>: <h:inputText id="vcKeterangan" value="#{MasterRekening.vcketerangancreate}" /></td>
</tr>
<tr>
<td><h:outputLabel value="Limit" for="NLimit" /></td>
<td>: <h:inputText value="#{MasterRekening.nlimitcreate}" id="NLimit" /></td>
</tr>
<tr>
<td><h:outputText value="Kode Currency :" /></td>
<td>:
<p:selectOneMenu value="#{MasterRekening.current.mscurrency0}" panelStyle="width:350px" converter="#{converterMScurrency}"
effect="fade" var="kdcura" style="width:160px" filter="true"
filterMatchMode="startsWith" >
<f:selectItems value="#{MasterRekening.mscurrency0List}" var="kdcur"
itemLabel="#{kdcur.vcKetcur}" itemValue="#{kdcur}"/>
<p:column>
#{kdcura.CKodecur} - #{kdcura.vcKetcur}
</p:column>
</p:selectOneMenu>
</td>
</tr>
<tr>
<td><h:outputText value="Kode GL" /></td>
<td>:
<p:selectOneMenu value="#{MasterRekening.current.glaccms0}" panelStyle="width:350px" converter="#{converterGlaccms0}"
effect="fade" var="p" style="width:160px" filter="true" filterMatchMode="startsWith"
>
<f:selectItems value="#{MasterRekening.glaccms0List}" var="player"
itemLabel="#{player.vcGlket}" itemValue="#{player}"/>
<p:column>
#{p.CGlkode} - #{p.vcGlket}
</p:column>
</p:selectOneMenu>
</td>
</tr>
<tr>
<td><h:outputText value="Tipe " /></td>
<td>:
<p:selectOneMenu value="#{MasterRekening.ctipecreate}">
<f:selectItem itemLabel="Kas" itemValue="1" />
<f:selectItem itemLabel="Bank" itemValue="2" />
<f:selectItem itemLabel="Credit" itemValue="3" />
</p:selectOneMenu>
</td>
</tr>
<tr>
<td><h:outputText value="Status " /></td>
<td>:
<p:selectOneMenu value="#{MasterRekening.cstatcreate}" id="CStat" >
<f:selectItem itemLabel="Aktif" itemValue="A" />
<f:selectItem itemLabel="Tidak Aktif" itemValue="D" />
</p:selectOneMenu>
</td>
</tr>
<tr>
<td><h:outputText value="Masuk Jurnal " /></td>
<td>:
<p:selectOneMenu value="#{MasterRekening.cdstatuscreate}" >
<f:selectItem itemLabel="Ya" itemValue="*******J**" />
<f:selectItem itemLabel="Tidak" itemValue="**********" />
<f:selectItem itemLabel="Hanya Saldo" itemValue="********R*" />
</p:selectOneMenu>
</td>
</tr>
<tr>
<td colspan="2">
<p:commandButton value="Create" oncomplete="carDialogscreate.hide()" update=":form:ListKsRekening"
actionListener ="#{MasterRekening.create()}" ajax="true" process="@all" id="create" >
</p:commandButton>
</td>
</tr>
</table>
</h:form>
</p:dialog>
</h:panelGrid>
这是我的更新对话框,当我更新数据表时不会创建空值
<h:panelGrid id="displayedit" columns="2" cellpadding="4">
<p:dialog id="dialogedit" header="Edit Rekening" widgetVar="carDialogedit" resizable="true"
showEffect="clip" hideEffect="fold" >
<h:form id="dlgFormedit">
<table>
<tr>
<td><h:outputLabel value="Kode Rekening" for="CRekening" /></td>
<td>: <h:inputText id="CRekening" value="#{MasterRekening.crekeningedit}" /></td>
</tr>
<tr>
<td><h:outputLabel value="Keterangan" for="vcKeterangan" /></td>
<td>: <h:inputText id="vcKeterangan" value="#{MasterRekening.vcketeranganedit}" /></td>
</tr>
<tr>
<td><h:outputLabel value="Limit" for="NLimit" /></td>
<td>: <h:inputText value="#{MasterRekening.nlimitedit}" id="NLimit" /></td>
</tr>
<tr>
<td><h:outputText value="Kode Currency :" /></td>
<td>:
<p:selectOneMenu value="#{MasterRekening.selected.mscurrency0}" panelStyle="width:350px" converter="#{converterMScurrency}"
effect="fade" var="kdcura" style="width:160px" filter="true"
filterMatchMode="startsWith" >
<f:selectItems value="#{MasterRekening.mscurrency0List}" var="kdcur"
itemLabel="#{kdcur.vcKetcur}" itemValue="#{kdcur}"/>
<p:column>
#{kdcura.CKodecur} - #{kdcura.vcKetcur}
</p:column>
</p:selectOneMenu>
</td>
</tr>
<tr>
<td><h:outputText value="Kode GL :" /></td>
<td>:
<p:selectOneMenu value="#{MasterRekening.selected.glaccms0}" panelStyle="width:350px" converter="#{converterGlaccms0}"
effect="fade" var="p" style="width:160px" filter="true" filterMatchMode="startsWith"
>
<f:selectItems value="#{MasterRekening.glaccms0List}" var="player"
itemLabel="#{player.vcGlket}" itemValue="#{player}"/>
<p:column>
#{p.CGlkode} - #{p.vcGlket}
</p:column>
</p:selectOneMenu>
</td>
</tr>
<tr>
<td><h:outputText value="Tipe : " /></td>
<td>:
<p:selectOneMenu value="#{MasterRekening.ctipeedit}">
<f:selectItem itemLabel="Kas" itemValue="1" />
<f:selectItem itemLabel="Bank" itemValue="2" />
<f:selectItem itemLabel="Credit" itemValue="3" />
</p:selectOneMenu>
</td>
</tr>
<tr>
<td><h:outputText value="Status : " /></td>
<td>:
<p:selectOneMenu value="#{MasterRekening.cstatedit}" id="CStat" >
<f:selectItem itemLabel="Aktif" itemValue="A" />
<f:selectItem itemLabel="Tidak Aktif" itemValue="D" />
</p:selectOneMenu>
</td>
</tr>
<tr>
<td><h:outputText value="Masuk Jurnal : " /></td>
<td>:
<p:selectOneMenu value="#{MasterRekening.cdstatusedit}" >
<f:selectItem itemLabel="Ya" itemValue="*******J**" />
<f:selectItem itemLabel="Tidak" itemValue="**********" />
<f:selectItem itemLabel="Hanya Saldo" itemValue="********R*" />
</p:selectOneMenu>
</td>
</tr>
<tr>
<td colspan="2">
<p:commandButton value="Edit" oncomplete="carDialogedit.hide()" update=":form:ListKsRekening"
actionListener ="#{MasterRekening.update()}" id="update" >
</p:commandButton>
</td>
</tr>
</table>
</h:form>
</p:dialog>
</h:panelGrid>
我想我的问题是在这里
<p:selectOneMenu value="#{MasterRekening.current.glaccms0}" panelStyle="width:350px" converter="#{converterGlaccms0}"
effect="fade" var="p" style="width:160px" filter="true" filterMatchMode="startsWith"
>
<f:selectItems value="#{MasterRekening.glaccms0List}" var="player"
itemLabel="#{player.vcGlket}" itemValue="#{player}"/>
<p:column>
#{p.CGlkode} - #{p.vcGlket}
</p:column>
</p:selectOneMenu>
这里
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "c_kodegl", referencedColumnName = "c_glkode", insertable = false, updatable = false)
private Glaccms0 glaccms0;
和这里
public List<Ksrekening> getKsRekeningList() {
TypedQuery<Ksrekening> query =
em.createNamedQuery("Ksrekening.findAll", Ksrekening.class);
List<Ksrekening> results = query.getResultList();
return results;
}
public void setKsRekeningList(List<Ksrekening> ksRekeningList) {
this.ksRekeningList = ksRekeningList;
}
加
<p:column id="kolomketeranganckodegl" filterBy="#{item.glaccms0.vcGlket}"
headerText="Keterangan Gl" footerText="Keterangan GL"
filterMatchMode="contains" >
<h:outputText value="#{item.glaccms0.vcGlket}"/>
</p:column>