<p:ajax> 无法将 <p:ajax> 附加到非 ClientBehaviorHolder 父级

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19955543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 11:08:39  来源:igfitidea点击:

<p:ajax> Unable to attach <p:ajax> to non-ClientBehaviorHolder parent

ajaxjsfjsf-2primefaces

提问by Bellil Med Samouel

I use JSF 2 , primefaces 4.0 and i try to use DataTable - In-Cell Editing as it's produced in primefaces showcase, but i have an error althought i copied the same example shown in showcase the error is

我使用 JSF 2、primefaces 4.0 并尝试使用 DataTable - 单元格内编辑,因为它是在 primefaces 展示中生成的,但是我有一个错误,尽管我复制了展示中显示的相同示例,错误是

<p:ajax> Unable to attach <p:ajax> to non-ClientBehaviorHolder parent

this is the xhtmlpagecode

这是 xhtmlpagecode

 <rich:panel  style="width : 800px; height : 551px; " > 
     <f:facet name="header" >

<h:outputText value="Tableau des articles" align="center" style="FONT-SIZE: small;"/>
            </f:facet>


    <h:form id="form">

   <p:dataTable id="cars" var="car" value="#{articlesbean.LMatpilotaccess1}" editable="true" editMode="cell" widgetVar="carsTable">  

        <f:facet name="header">  
            Matériel du pilotage et accesstheitroades 
        </f:facet>  
  <p:growl id="messages" showDetail="true"/>  

    <p:contextMenu for="cars" widgetVar="cMenu">     
        <p:menuitem value="Edit Cell" icon="ui-icon-search" onclick="PF('carsTable').showCellEditor();return false;"/>    
        <p:menuitem value="Hide Menu" icon="ui-icon-close" onclick="PF('cMenu').hide()"/>    
    </p:contextMenu>   


        <p:column headerText="Serie" style="width:25%">  
               <p:ajax event="cellEdit" listenner="#{articlesbean.onCellEdit}" update=":form:messages" /> 

               <p:cellEditor>  
                   <f:facet name="output"><h:outputText value="#{car.serie}" /></f:facet>  
                   <f:facet name="input"><p:inputText id="modelInput" value="#{car.serie}" style="width:96%"/></f:facet>  
               </p:cellEditor>  
           </p:column>  



    </p:dataTable>  


    </h:form>




</rich:panel>

and this is my bean

这是我的豆子

@ManagedBean(name="articlesbean")

@ViewScoped
public class ArticlesBean implements Serializable{

    @Inject
    private ArticlesDAO articleDAO;
    @Inject
    private Matpilotaccess1 matpilotaccess1;
    @Inject
    private Matpilotaccess2 matpilotaccess2;
    @Inject
    private Poteaux poteaux ;
    @Inject
    private Travgc1 travgc1;
    @Inject
    private Travgc2 travgc2;
    @Inject
    private Travresurbain travresurbain;


    private List LMatpilotaccess1 = new ArrayList();
    private List LMatpilotaccess2 = new ArrayList();
    private List LPoteaux = new ArrayList();
    private List LTravgc1 = new ArrayList();
    private List LTravgc2 = new ArrayList();
    private List LTravresurbain = new ArrayList();




    public void onCellEdit(CellEditEvent event) {  
        Object oldValue = event.getOldValue();  
        Object newValue = event.getNewValue();  

        if(newValue != null && !newValue.equals(oldValue)) {  
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);  
            FacesContext.getCurrentInstance().addMessage(null, msg);  
        }  
    } 

    //// Getters and setters

回答by BalusC

You nested the <p:ajax>inside a <p:column>. The <p:ajax>requires to be nested in a component implementing the ClientBehaviorHolderinterface. However, the Columncomponent classbehind <p:column>does not implement it. The DataTablecomponent classbehind <p:dataTable>implements it.

你嵌套了<p:ajax>里面的<p:column>. 该<p:ajax>要求被嵌套在实现的组件ClientBehaviorHolder接口。但是后面的Column组件类<p:column>并没有实现。后面的DataTable组件类<p:dataTable>实现了它。

You should be nesting <p:ajax>inside <p:dataTable>instead:

你应该嵌套<p:ajax>在里面<p:dataTable>

<p:dataTable ...>
   <p:ajax ... /> 

   <p:column ...>
       ...
   </p:column>
</p:dataTable>

Exactly as demonstrated on their showcase site. In other words, your statement

与他们的展示网站上展示的完全一样。换句话说,你的陈述

althought i copied the same example shown in showcase

虽然我复制了展示中显示的相同示例

is actually not true.

事实并非如此。