【发布时间】:2017-06-23 02:23:42
【问题描述】:
p:datagrid 的单元编辑器中的 p:commandLink 或 p:commandButton 不起作用,当我单击 commandLink 时,它会将我重定向到同一页面。在 celleditor 内部,commandLink 找不到它的监听器,但是当我将它带到 celleditor 外部时,它可以正常工作。
<h:form id="form">
<p:growl id="msgs" showDetail="true"/>
<p:dataTable id="project" var="car" value="#{editdeleteview.proj_rec}" rowKey="#{car.id}" selection="#{editdeleteview.selected_rec}" selectionMode="single" editable="true" style="margin-bottom:20px">
<f:facet name="header">
All Projects
</f:facet>
<p:ajax event="rowEdit" listener="#{editdeleteview.onRowEdit}" update=":form:msgs"/>
<p:ajax event="rowEditCancel" listener="#{editdeleteview.onRowCancel}" update=":form:msgs"/>
<p:column headerText="ID">
<h:outputLabel value="#{car.id}" />
</p:column>
<p:column headerText="Title">
<p:commandLink ajax="false" action="#{editdeleteview.openObjects(car)}" ><h:outputText value="#{car.title}" /></p:commandLink>
<p:cellEditor>
<f:facet name="output"><p:commandLink ajax="false" action="#{editdeleteview.openObjects(car)}" ><h:outputText value="#{car.title}" /></p:commandLink></f:facet>
<f:facet name="input"><p:inputText value="#{car.title}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Description">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{car.description}" /></f:facet>
<f:facet name="input"><p:inputText value="#{car.description}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Insertion Time">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{car.insertionTimestamp}" /></f:facet>
<f:facet name="input"><p:inputText value="#{car.insertionTimestamp}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Close Time">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{car.closeTimestamp}" /></f:facet>
<f:facet name="input"><p:inputText value="#{car.closeTimestamp}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit" style="width:50px">
<p:rowEditor />
</p:column>
<p:column headerText="Delete">
<p:commandButton id="downloadLink1" value="Delete" ajax="false" class="btn btn-danger" icon="ui-icon-trash" action="#{editdeleteview.delete(car)}">
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
列标题下单元编辑器外部的 p:commandLink 工作正常,但在单元编辑器内部,commandLink 不起作用,bean 中的侦听器是
public String openObjects(Project p)
{
HttpSession session = SessionUtils.getSession();
session.setAttribute("project_id", p.getId());
session.setAttribute("project_title", p.getTitle());
//session.setAttribute("project_title", "Hamdan");
System.out.println("EditView: "+session.getAttribute("project_title").toString());
return "Objects.xhtml";
}
我也试过这个commandLink in cellEditor doesn't trigger action/actionListener 但这对我没有用。任何帮助将不胜感激。
【问题讨论】:
-
'不工作'是含糊不清的。您的其他问题之一被标记为某事的副本。该副本包含有关如何进一步调试的信息。请做。
-
@Kukeltje 我也试过了,我提到了“标题”列下 cellEditor 内的 commandlink 没有调用它的侦听器并且只是在同一页面上重定向而没有任何错误的问题。跨度>
-
@Kukeltje cellEditor 标签外的 commandLink 工作正常,但我希望 cellEditor 内的 commandLink 工作。
-
是的,我知道你想要什么,但你可以调试更多。如果您说它正在重定向,那只能由服务器完成,因此该按钮确实会调用某些东西。或者它只是停留在同一页面上并且什么都不做?或者事情是否焕然一新。检查网络流量(请求和响应),调试 faces servlet 等等。所有你能做的事情都应该先自己做。并发布版本信息...
-
首先,您的 p:commandLink 中有一个 ajax="false",它创建了一个无 ajax 导航,因此刷新了您的页面。检查一下。
标签: jsf primefaces datagrid