这是Primefaces错误还是Mojarra/MyFaces错误 [英] Is this Primefaces bug or Mojarra/MyFaces bug

查看:91
本文介绍了这是Primefaces错误还是Mojarra/MyFaces错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我位于dataTablecolumn之内时,似乎无法触发事件.这是我简单的演示

I cannot seems to be able to fire an event when I am within column of dataTable. Here is my simple demostration

<h:form id="form">
    <!--This section of p:tree here seems to be the reason causing the event not fired when click the command button-->
    <p:tree value="#{viewBean.root}" var="node" dynamic="true" cache="false"  
                selectionMode="checkbox"  selection="#{treeBean.selectedNode}">  

        <p:ajax event="expand" update=":form:messages" listener="#{viewBean.onNodeExpand}" />  
        <p:ajax event="collapse" update=":form:messages" listener="#{viewBean.onNodeCollapse}" />  
        <p:ajax event="select" update=":form:messages" listener="#{viewBean.onNodeSelect}" />  
        <p:ajax event="unselect" update=":form:messages" listener="#{viewBean.onNodeUnselect}" />  

        <p:treeNode>  
            <h:outputText value="#{node}" />  
        </p:treeNode>  
    </p:tree>
    <h:panelGroup id="mygroup">
            <p:dataTable id="mytable" value="#{viewBean.foodList}" var="item">
                <p:column>
                    #{item}
                </p:column>
                <p:column>
                    <p:commandButton value="delete" 
                                     action="#{viewBean.delete}"
                                     update=":form:mygroup">
                        <f:setPropertyActionListener target="#{viewBean.selectedFood}"
                                                     value="#{item}"/>
                    </p:commandButton>
                </p:column>
            </p:dataTable>
    </h:panelGroup>
</h:form>

这是我的托管bean

and here is my managed bean

@ManagedBean
@ViewScoped
public class ViewBean {

    private TreeNode root;  

    private TreeNode selectedNode;  
    private List<String> foodList;

    private String selectedFood;

    @PostConstruct
    public void init(){

        foodList = new ArrayList<String>();
        foodList.add("Pizza");
        foodList.add("Pasta");
        foodList.add("Hamburger");

        root = new DefaultTreeNode("Root", null);  
        TreeNode node0 = new DefaultTreeNode("Node 0", root);  
        TreeNode node1 = new DefaultTreeNode("Node 1", root);  
        TreeNode node2 = new DefaultTreeNode("Node 2", root);  

        TreeNode node00 = new DefaultTreeNode("Node 0.0", node0);  
        TreeNode node01 = new DefaultTreeNode("Node 0.1", node0);  

        TreeNode node10 = new DefaultTreeNode("Node 1.0", node1);  
        TreeNode node11 = new DefaultTreeNode("Node 1.1", node1);  

        TreeNode node000 = new DefaultTreeNode("Node 0.0.0", node00);  
        TreeNode node001 = new DefaultTreeNode("Node 0.0.1", node00);  
        TreeNode node010 = new DefaultTreeNode("Node 0.1.0", node01);  

        TreeNode node100 = new DefaultTreeNode("Node 1.0.0", node10);  
    }

    public void delete(){

        foodList.remove(selectedFood);

    }
    //setter and getter

    public void onNodeExpand(NodeExpandEvent event) {  
       FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Expanded", event.getTreeNode().toString());  

       FacesContext.getCurrentInstance().addMessage(null, message);  
    }  

    public void onNodeCollapse(NodeCollapseEvent event) {  
       FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Collapsed", event.getTreeNode().toString());  

       FacesContext.getCurrentInstance().addMessage(null, message);  
    }  

    public void onNodeSelect(NodeSelectEvent event) {  
       FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Selected", event.getTreeNode().toString());  

       FacesContext.getCurrentInstance().addMessage(null, message);  
    }  

    public void onNodeUnselect(NodeUnselectEvent event) {  
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Unselected", event.getTreeNode().toString());  

        FacesContext.getCurrentInstance().addMessage(null, message);  
    }  
}

我的问题似乎是未触发该事件,这意味着delete从不被调用.

My problem seems to be that the event is not fired, meaning delete never get invoked.

我环顾四周,并且知道Mojarra嵌套UIData组件有很多问题,因此我尝试使用Mojarra 2.1.4,但仍然没有解决问题.我尝试了Myfaces 2.1.5,仍然无法正常工作!!!这是Primefaces的错误吗?我什至将h:panelGroup用作update的包装,但仍然无法正常工作.

I have look around, and know that Mojarra have ton of issues with nested UIData components, so I tried Mojarra 2.1.4, still did not solved the problem. I tried Myfaces 2.1.5, still does not work!!! Is this a Primefaces bugs? I even use h:panelGroup as a wrapper for update but it still does not work.

编辑:事实证明,dataTable上方的p:tree是单击commandButton时未触发事件的根本原因.如果删除p:tree,则可以立即使用.请注意,当我单击结帐时,p:tree本身可以很好地运行,该事件在托管bean上触发.

EDIT: It turn out that the p:tree above the dataTable is the root cause of the event not fired when clicking the commandButton. If I remove the p:tree then it work immediately. Note that the p:tree itself work great, as I click on the checkout, event fired on my managed bean.

推荐答案

这是您自己的代码中的错误.

It's a bug in your own code.

<partial-response>
  <error>
    <error-name>class javax.el.ELException</error-name>
    <error-message><![CDATA[/index.xhtml @15,84 selection="#{viewBean.selectedNode}": Cannot convert [Lorg.primefaces.model.TreeNode;@fd9b4d of type class [Lorg.primefaces.model.TreeNode; to interface org.primefaces.model.TreeNode]]></error-message>
  </error>
</partial-response>

具体的异常消息建议<p:tree selection>应该引用类型为TreeNode[]而不是TreeNode的属性(请注意消息中类标识符的[前缀,它指示数组类型).因此,请相应地对其进行修复:

The concrete exception message suggests that the <p:tree selection> is expected to refer a property of type TreeNode[] and not TreeNode (note the [ prefix on the class identifier in the message which indicates an array type). So, fix it accordingly:

<p:tree selection="#{treeBean.selectedNodes}">

使用

private TreeNode[] selectedNodes;

无论如何,您都将<p:tree><p:dataTable>都包含在一个相同的上帝"形式中.因此,它们中的任何一个动作都将提交其他组件上的所有内容.如果树和表之间没有任何关联,则应将它们分别放在自己的<h:form>中.或者,您必须在命令链接/按钮中添加process属性,以仅处理感兴趣的包含组件,例如process="mytable"在表格内的按钮上.

Regardless, you've both the <p:tree> and <p:dataTable> inside the one and same "god" form. So any action in either of them will submit everything on the other component as well. If the tree and the table are in no way related to each other, then they should each be placed in its own <h:form>. Or, you must add a process attribute to the command links/buttons to process only the containing component of interest, e.g. process="mytable" on the button inside the table.

这篇关于这是Primefaces错误还是Mojarra/MyFaces错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆