我有以下页面,不知何故
<p:commandButton value="Save" update="data" oncomplete="edit.hide();" actionListener="#{dataBean.update}" />
不会调用actionListener中指定的方法。我检查了this post的所有选项,一切似乎都是正确的。我错过了什么吗?
Page
<h:body id="body" style="margin:50px; font-size: 80%">
<f:view contentType="text/html">
<h:form>
<p:ajaxStatus onstart="statusDialog.show();"
onsuccess="statusDialog.hide();" />
<p:dialog modal="true" widgetVar="statusDialog" header="Processing"
draggable="false" closable="false" resizable="false" width="255">
<p:graphicImage value="./images/ajax-loader.gif" />
</p:dialog>
<p:commandButton value="Delete selected"
onclick="confirmationSelected.show()" />
<p:commandButton value="Refresh data" update="data"
style="float:right" actionListener="#{dataBean.refresh}" />
<p:dataTable var="item" value="#{dataBean.records}" id="data"
paginator="true" rows="10" selection="#{dataBean.selectedRecords}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15,20,25,50,100">
<f:facet name="header">Stored records</f:facet>
<p:column selectionMode="multiple" />
<p:column style="width:18px; text-align:center;">
<p:rowToggler />
</p:column>
<p:column headerText="Time" style="width:80px; text-align:center;"
sortBy="#{item.time}" filterby="#{item.time}"
filterMatchMode="contains">
<h:outputText value="#{item.time}">
<f:convertDateTime type="both" dateStyle="short" />
</h:outputText>
</p:column>
<p:column headerText="URL" style="word-break: break-all"
sortBy="#{item.url}" filterby="#{item.url}"
filterMatchMode="contains">
<h:outputText value="#{item.url}" />
</p:column>
<p:column headerText="Rating" style="width:80px; text-align:center;"
sortBy="#{item.rating}" filterby="#{item.rating}"
filterMatchMode="contains">
<h:outputText value="#{item.rating}" />
</p:column>
<p:column headerText="Key" style="width:80px; text-align:center;"
sortBy="#{item.key}" filterby="#{item.key}"
filterMatchMode="contains">
<h:outputText value="#{item.key}" />
</p:column>
<p:column headerText="Actions"
style="text-align:center; width:100px;">
<p:commandLink value="Edit" oncomplete="edit.show()"
update="editPanel">
<f:setPropertyActionListener target="#{dataBean.key}"
value="#{item.key}" />
</p:commandLink>
<p:commandLink value="Delete" onclick="confirmation.show()">
<f:setPropertyActionListener target="#{dataBean.key}"
value="#{item.key}" />
</p:commandLink>
</p:column>
<p:rowExpansion>
<p:tabView>
<p:tab title="Page source">
<div
style="max-height: 300px; overflow-y: auto; word-break: break-all">#{item.page}</div>
</p:tab>
<p:tab title="Snippet">
<div
style="max-height: 300px; overflow-y: auto; word-break: break-all">#{item.snippet}</div>
</p:tab>
</p:tabView>
</p:rowExpansion>
</p:dataTable>
<p:confirmDialog message="Are you sure you want to delete this item?"
header="Delete" severity="alert" widgetVar="confirmation"
modal="true">
<p:commandButton value="OK" oncomplete="confirmation.hide()"
actionListener="#{dataBean.deleteOne}" update="data" />
<p:commandLink value="Cancel" onclick="confirmation.hide()" />
</p:confirmDialog>
<p:confirmDialog
message="Are you sure you want to delete all selected items?"
header="Delete" severity="alert" widgetVar="confirmationSelected"
modal="true">
<p:commandButton value="Delete"
oncomplete="confirmationSelected.hide()"
actionListener="#{dataBean.deleteSelected}" update="data" />
<p:commandLink value="Cancel" onclick="confirmationSelected.hide()" />
</p:confirmDialog>
</h:form>
<p:dialog header="Edit record" widgetVar="edit" resizable="true"
width="850" height="500" modal="true">
<h:form id="editPanel">
<h:outputText value="Record ID = #{dataBean.selectedRecordKey}"
style="font-size:12pt;" />
<p:separator />
<h:panelGrid columns="6">
<h:outputText style="margin-left:-2px;" value="Time:" />
<h:inputText value="#{dataBean.selectedRecordTime}"
style="width: 230px" />
<h:outputText style="margin-left:20px;" value="Url:" />
<h:inputText value="#{dataBean.selectedRecordUrl}"
style="width: 375px" />
<h:outputText style="margin-left:20px;" value="Rating:" />
<p:spinner value="#{dataBean.selectedRecordRating}" min="1" max="5"
style="width: 30px" width="20" showOn="never" />
</h:panelGrid>
<br />
<p:tabView>
<p:tab title="Page source">
<h:inputTextarea value="#{dataBean.selectedRecordPage}" rows="13" cols="108" />
</p:tab>
<p:tab title="Snippet">
<h:inputTextarea value="#{dataBean.selectedRecordSnippet}" rows="13" cols="108" />
</p:tab>
</p:tabView>
<br />
<p:commandButton value="Save" update="data"
oncomplete="edit.hide();" actionListener="#{dataBean.update}" />
<p:commandLink value="Cancel" onclick="edit.hide()"
style="margin-left:10px;" />
</h:form>
</p:dialog>
</f:view>
答案 0 :(得分:1)
在对话框中,您将内容放在新表格中
<h:form id="editPanel">
您可以删除此表单并重新运行代码吗?
所以现在你的所有内容都应该放在你在这一行创建的一个表单中:
<f:view contentType="text/html">
<h:form>
答案 1 :(得分:0)
你能展示dataBean.update的声明吗?
通常,动作侦听器方法应返回void并将ActionEvent作为参数。
您是否尝试使用操作而不是actionListener?