【问题标题】:The p:commandLink inside the p:datagrid's p:celleditor is not workingp:datagrid 的 p:celleditor 中的 p:commandLink 不起作用
【发布时间】: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


【解决方案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>

【讨论】:

  • process="@this" 修复了它。 TY
【解决方案2】:

尝试在您的命令链接组件上设置immediate="true"。 看看@BalusC 的解释:

Trying to understand immediate="true" skipping inputs when it shouldn't

【讨论】:

  • cellEditor 外的 commandButton 有效,所以如果这是解决方案,最好解释一下为什么在 cellEditor 的上下文中它需要而不是 就在它外面。
  • 我建议将其作为一种解决方案,以防万一。其实自己没试过。但我认为这解决了这个问题,因为 cellEditor 内的 commandLink 请求可能受 cellEditor 自己的事件或我猜测的请求的限制。 @Kukeltje 如果答案不符合规则,请随意投反对票。别往心里放。 :)
  • 不,不反对,因为我不知道它是否有帮助。但是,如果您还没有尝试过,最好下次发布这样的简短内容作为评论,如果有帮助,请将其转换为答案。问题中提到的process="this" 解决或应该解决您所描述的问题
【解决方案3】:

我正在使用 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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-09
    • 1970-01-01
    • 1970-01-01
    • 2020-01-02
    • 1970-01-01
    • 1970-01-01
    • 2016-11-30
    • 2012-07-16
    相关资源
    最近更新 更多