Tôi muốn tạo biểu mẫu chỉnh sửa cho bảng Primefaces. Tôi đã thử nghiệm mã này: đậuTạo biểu mẫu chỉnh sửa cho bảng Primefaces
<h:form id="form">
<p:dataTable id="tbl" var="systemuser" value="#{systemusers.systemUsers}"
selectionMode="single" selection="#{systemusers.selectedSystemUser}" rowKey="#{systemuser.username}" lazy="true"
resizableColumns="true"
>
<p:ajax event="rowSelect" listener="#{systemusers.onRowSelect}" update=":form:carDetail" oncomplete="PF('carDialog').show()" />
....................
</p:dataTable>
<p:dialog id="wd" header="System User Details" widgetVar="carDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="true">
<p:outputPanel id="carDetail" style="text-align:center;">
<p:panelGrid columns="2" columnClasses="label,value">
<h:outputLabel for="id" value="ID" />
<p:outputLabel id="id" value="#{systemusers.selectedSystemUser.id}" rendered="#{not systemusers.editable}"/>
<h:inputText value="#{systemusers.selectedSystemUser.id}" rendered="#{systemusers.editable}" />
........
</p:panelGrid>
</p:outputPanel>
<f:facet name="footer">
<p:commandButton value="Edit System User" rendered="#{not systemusers.editable}"
actionListener="#{systemusers.editRecord(false)}">
<f:ajax render=":form:wd" execute=":form:wd"></f:ajax>
</p:commandButton>
<p:commandButton value="Cancel" rendered="#{systemusers.editable}" actionListener="#{systemusers.editRecord(true)}">
<f:ajax render=":form" execute=":form"></f:ajax>
</p:commandButton>
</f:facet>
</p:dialog>
<p:contextMenu for="tbl">
<p:menuitem value="View" update="carDetail" icon="fa fa-search" oncomplete="PF('carDialog').show()"/>
<p:menuitem value="Delete" update="tbl" icon="fa fa-remove" actionListener="#{systemusers.deleteSystemUser}">
<p:confirm header="Confirmation" message="Are you sure?" icon="fa fa-warning" />
</p:menuitem>
</p:contextMenu>
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
<p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="fa fa-check" />
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="fa fa-remove" />
</p:confirmDialog>
</h:form>
Managed:
@Named
@RequestScoped
public class Systemusers implements Serializable
{
.......
public void editRecord(boolean editable)
{
SessionFactory factory = HibernateUtils.getSessionFactory();
Session session = factory.getCurrentSession();
try
{
session.getTransaction().begin();
SystemUsersModel obj = new SystemUsersModel();
obj.setId(selectedSystemUser.getId());
..........
session.update(obj);
session.getTransaction().commit();
this.editable = editable;
}
catch (Exception e)
{
e.printStackTrace();
session.getTransaction().rollback();
}
}
......
private boolean editable = false;
public boolean isEditable()
{
return editable;
}
public void setEditable(boolean editable)
{
this.editable = editable;
}
}
Khi tôi mở biểu mẫu Chỉnh sửa và tôi bấm nút Edit System User
hình thức biến mất. Có lẽ vì tôi render và thực hiện nó. Làm thế nào tôi có thể thực hiện các hình thức và dưới nó mà không đóng nó?
Tôi đã thử nhưng tôi nhận được kết quả tương tự. Bạn có thể dán một số ví dụ mã? –
Tôi đã thử đề xuất của bạn nhưng một lần nữa hộp thoại bị ẩn. Tôi đã thêm biểu mẫu vào hộp thoại và giờ đây tôi đã giải quyết được vấn đề. Hiện tại tôi đang đối mặt với vấn đề này: Java Object value = "# {systemusers.selectedSystemUser.id}" trống rồi tôi nhấn nút chỉnh sửa. Bất kỳ ý tưởng làm thế nào tôi có thể sửa lỗi này? –
Một lưu ý nhanh ở đây là bạn tốt hơn có một h: hình thức dành riêng cho hộp thoại và một cho bảng, cố gắng để bọc ** nội dung ** của p: hộp thoại với một h: hình thức mới và để dataTable của bạn với cũ h: hình thức, điều này có thể dẫn bạn sửa bất kỳ vấn đề xử lý hoặc xử lý sai nào. –