p:commandLink或p:commandButton在p:datagrid的celleditor中不起作用,当我点击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>
列标题下的celleditor外的p:commandLink工作正常,但在celleditor内部,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,但这对我没用。任何帮助将受到高度赞赏。
答案 0 :(得分:1)
只需使用此功能即可使用
<f:facet name="output">
<p:commandLink action="#{editdeleteview.openObjects(car)}"
process="@this" immediate="true">
<h:outputText value="#{car.title}" />
<f:setPropertyActionListener
target="#{editdeleteview.selected_rec}" value="#{car}" />
</p:commandLink>
</f:facet>
答案 1 :(得分:0)
尝试在命令链接组件上设置immediate="true"
。
看看@BalusC的解释:
Trying to understand immediate="true" skipping inputs when it shouldn't
答案 2 :(得分:0)
我使用的是primefaces 6.3-SNAPSHOT,这个问题仍然存在,这就是我解决的方法:
JSF:
<p:commandLink ajax="false" action="#{editdeleteview.openObjects(car)}" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.title}" />
</f:facet>
<f:facet name="input">
<p:inputText onclick="stopEventPropagation(event)" value="#{car.title}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:commandLink>
JAVASCRIPT:
function stopEventPropagation(event){
event.stopPropagation();
return false;
}