我正在研究JSF/PrimeFaces,但当我使用来自PrimeFace的菜单项时,我的表面板不会自动工作。
<p:menuitem value="Hide Group" icon="ui-icon-close" styleClass="delete-group" onclick="pw_confirm_apply_end_date.show();return false" update="pnl_tbl_addr_group_mst" />
<p:confirmDialog widgetVar="pw_confirm_apply_end_date" message="Do you want to continue with applying end date?" style="width:300px">
<p:commandButton id="btn_update_dlg" value="Apply End Date" icon="ui-icon-clock" process="@this" update=":form1:pnl_tbl_addr_group_mst,growl1" oncomplete="pw_confirm_apply_end_date.hide()" actionListener="#{addmst_grid.hideGroup}" />
<p:commandButton value="Cancel" icon="ui-icon-close" onclick="pw_confirm_apply_end_date.hide();return false;" />
</p:confirmDialog>
当用户点击"隐藏组"按钮时,它会显示符合框,在他们按下"应用"后,组可以隐藏,但面板更新不起作用。
public void hideGroup(ActionEvent event) {
FcadAddrGrpMst ent_AddrGrpMst = fcadAddrGrpMstFacade.find(selectedGroupMst.getAgmUniqueSrno());
FacesContext context = FacesContext.getCurrentInstance();
try {
ent_AddrGrpMst.setEndDate(new Date());
ent_AddrGrpMst.setUpdateby(new FhrdEmpmst(globalData.getUser_id()));
fcadAddrGrpMstFacade.edit(ent_AddrGrpMst);
try {
setTbl_addr_group_mst();
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Hide Group", "Hide Group successfully"));
} catch (Exception e) {
logGenerator.generateLog(system_Properties.getSystemName(), Level.SEVERE, this.getClass().getName(), "hideGroup", null, e);
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Error in resetting components", "Hide Group successfully but error in resetting component(s) please refresh the page to view the changes"));
}
} catch (Exception e) {
logGenerator.generateLog(system_Properties.getSystemName(), Level.SEVERE, this.getClass().getName(), "hideGroup", null, e);
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Some unexpected error occurred while saving record(s)"));
}
}
onclick是在客户端处理的,但更新是在ajax事件之后完成的。为了使更新生效,您需要进行一些ajax调用,比如p:menuitem操作或actionListener调用服务器端方法。