在执行某些操作后,我遇到了更新dataTable的问题。例如,当我尝试按新用户按钮添加新用户时,我无法添加第二个,因为按钮是“非活动”。我尝试update =“dataTable”和update =“:form:dataTable”,没有成功。有人能告诉我我做错了吗?
<ui:composition template="../adminTemplates/layout.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<ui:define name="content">
<h:form id="form" prependId="false">
<p:growl id="messages" showDetail="true" />
<p:contextMenu for="dataTable">
<p:menuitem value="Delete" update="dataTable" icon="ui-icon-close"
actionListener="#{userMB.deleteUser}" />
</p:contextMenu>
<p:dataTable id="dataTable" var="user" value="#{userMB.userList}"
paginator="true" rows="5" rowKey="#{user.user_id}"
selection="#{userMB.selectedUser}" selectionMode="single"
filteredValue="#{userMB.filteredUsers}" editable="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<p:ajax event="rowEdit" immediate="true" listener="#{userMB.onEdit}"
update=":form:messages, :form:dataTable" />
<f:facet name="header">
Students
</f:facet>
<p:column sortBy="name" filterBy="name" id="name" headerText="Name">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.name}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{user.name}" required="true"
requiredMessage="Please Enter Name"
validatorMessage="Name is too short!">
<f:validateLength minimum="2"></f:validateLength>
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column sortBy="surname" filterBy="surname" headerText="Surname">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.surname}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{user.surname}" required="true"
requiredMessage="Please Enter Surname!"
validatorMessage="Surname is too short!">
<f:validateLength minimum="2"></f:validateLength>
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column sortBy="username" filterBy="username"
headerText="Index number">
<h:outputText value="#{user.username}" />
</p:column>
<p:column sortBy="userDescription" filterBy="userDescription"
headerText="Faculty">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.userDescription}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{user.userDescription}" required="true"
requiredMessage="Please Enter User Description" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:6%" headerText="Edit">
<p:rowEditor />
</p:column>
<f:facet name="footer">
<p:commandButton value="New User" oncomplete="newUserDialog.show()"
icon="ui-icon-star" title="Creates new user" />
</f:facet>
</p:dataTable>
</h:form>
<p:dialog header="Create New User" widgetVar="newUserDialog"
resizable="false" id="newUserDlg">
<h:form id="newUserForm">
<p:messages autoUpdate="true" />
<p:panelGrid id="displayNewUser" columns="2" cellpadding="4"
style="margin:0 auto;">
<h:outputText value="Name :"></h:outputText>
<p:inputText id="name" value="#{userMB.name}" required="true"
requiredMessage="Please Enter Name"
validatorMessage="Name is too short!">
<f:validateLength minimum="2"></f:validateLength>
</p:inputText>
<h:outputText value="Surname :"></h:outputText>
<p:inputText id="Surname" value="#{userMB.surname}" required="true"
requiredMessage="Please Enter Surname!"
validatorMessage="Surname is too short!">
<f:validateLength minimum="2"></f:validateLength>
</p:inputText>
<h:outputText value="Index_num :" />
<p:inputText id="indexx" value="#{userMB.username}" required="true"
requiredMessage="Please Enter Index Number"
validatorMessage="Index Number should have 6 numbers!">
<f:validateLength minimum="6" maximum="6" />
<f:validateRegex pattern="^[0-9]+$" />
</p:inputText>
<h:outputText value="PESEL :"></h:outputText>
<p:inputText value="#{userMB.password}" required="true"
requiredMessage="Please Enter PESEL!"
validatorMessage="PESEL should have last 5 numbers!">
<f:validateLength minimum="5" maximum="5" />
<f:validateRegex pattern="^[0-9]+$" />
</p:inputText>
<h:outputText value="User Description :"></h:outputText>
<p:inputText value="#{userMB.userDescription}" required="true"
requiredMessage="Please Enter User Description" />
<f:facet name="footer">
<p:commandButton value="Submit" actionListener="#{userMB.addUser}"
oncomplete=" handleSubmitRequest(xhr, status, args, 'newUserDlg','newUserForm');"
update=":form:dataTable, :growl" validateClient="true" />
<p:commandButton type="reset" value="Reset"></p:commandButton>
</f:facet>
</p:panelGrid>
</h:form>
</p:dialog>
<p:growl id="growl" showDetail="true" life="5000" />
<script type="text/javascript">
function handleSubmitRequest(xhr, status, args, dialogName,
formName) {
dialog = jQuery('#' + dialogName);
if (args.validationFailed) {
dialog.effect("shake", {
times : 3
}, 100);
} else {
clearForm(formName);
newUserDialog.hide();
userDialog.hide();
}
}
function clearForm(formName) {
jQuery('#' + formName).each(function() {
this.reset();
});
}
</script>
</ui:define>
</ui:composition>
答案 0 :(得分:1)
将代码更改为
<f:facet name="footer">
<p:commandButton value="New User" onclick="newUserDialog.show()"
icon="ui-icon-star" title="Creates new user" />
</f:facet>
更新:: 我有一个类似的实现,我正在分享我所做的,我找不到你的错。
<p:commandButton ajax="false" update=":ff1:actDetails:lis"
oncomplete="handleComplete(xhr, status, args)" value="Submit" actionListener="#{insertbean.insert()}" type="submit" />
actionListener="#{userMB.addUser}"
应该像actionListener="#{userMB.addUser()}"
我的javascript是
function handleComplete(xhr, status, args) {
if (!args.validationFailed) {
dlg1.hide();
} else {
}
}
dlg1是对话框widgetVar。对话框中的表单也有必需= true类型的验证,但我的对话框没有任何动画。
3.我使ajax =“false”因为ajax =“true”没有更新数据表新条目。
我的添加新按钮是
<f:facet name="footer">
<p:commandButton value="Add Activity" type="button" onclick="dlg1.show()" />
</f:facet>
愿它有所帮助。