2011-12-28 6 views
0

columndataTable 인 경우 이벤트를 실행할 수없는 것 같습니다. 여기 내 간단한 demostration이 Primefaces 버그 또는 Mojarra/MyFaces 버그입니까

여기
<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> 

및 내 관리 빈

@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 호출되지는 결코 의미하는 이벤트가 발생되지 않도록 할 것입니다.

나는 주변을 둘러 보았고 Mojarra에는 중첩 된 UIData 구성 요소와 관련된 문제점이 있으므로 Mojarra 2.1.4를 시도했지만 여전히 문제를 해결하지 못했습니다. 나는 Myfaces 2.1.5를 시도했지만 여전히 작동하지 않는다 !! 이것은 Primefaces 버그입니까? 심지어 h:panelGroupupdate에 대한 래퍼로 사용하지만 여전히 작동하지 않습니다.

편집 : 그것은 dataTable 위의 p:treecommandButton을 클릭하지 않을 경우 해고 이벤트의 근본 원인이라고 판명. p:tree을 제거하면 즉시 작동합니다. p:tree 자체가 훌륭하게 작동합니다. 체크 아웃을 클릭하면 내 관리 대상 Bean에서 이벤트가 실행됩니다.

+0

앞으로는 "작동하지 않는다"와 관련하여 좀 더 구체적으로 설명하십시오. 예 : "selectedFood는'delete()'메쏘드 안에서'null '입니다. – BalusC

+0

@BalusC : 죄송합니다. '게시물이 작동하지 않습니다.'라는 말의 의미를 명확히하기 위해 게시물을 편집했습니다. –

+1

좋습니다, 청어 청어를 피하려면 처음에 답을 게시 한 버그를 수정하는 것을 잊지 마십시오. 당신은 여전히 ​​"작동하지 않습니다"에 분명하지 않습니다. "해고 당하지 않는 사건"이란 정확히 무엇을 의미합니까? 예를 들어 Firebug/Chrome에 따라 아약스 요청이 전혀 전송되지 않았습니까? – BalusC

답변

5

이것은 자신의 코드에있는 버그입니다.

<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[]의 속성을 참조하는 것으로하고 있지 않은 것을 의미한다. 그래서, 적절하게 수정 :

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

private TreeNode[] selectedNodes; 

와 상관없이, 당신은 <p:tree>과 하나 같은 "신"형태로 내부 <p:dataTable> 모두를했습니다. 따라서 둘 중 하나의 작업도 다른 구성 요소의 모든 작업을 제출합니다. 나무와 테이블이 서로 관련이 없다면 각각은 자신의 <h:form>에 위치해야합니다. 또는 명령 링크/버튼에 process 속성을 추가하여 관심있는 포함 된 구성 요소 만 처리해야합니다 (예 : process="mytable"은 테이블 안의 버튼에 있습니다.

+0

BalusC에 감사드립니다. 우선'selectionMode = "single"'을 가지고,'selectionMode = "checkbox"'로 바꾼다.하지만 TreeNode []를 사용해야한다는 것을 알지 못했다. 고맙습니다. 마지막 질문은'Lorg.primefaces.model.TreeNode'는 TreeNode []를 의미합니까? –

+0

아니요, 'TreeNode'유형의 객체를 식별합니다. '[Lorg.primefaces.model.TreeNode'는'TreeNode' 타입의 객체들의 배열을 식별합니다. – BalusC

+0

나는 본다. 고맙습니다. 오늘 일부 디버깅 기술을 배우십시오 :) –