Este é um bug do Primefaces ou Mojarra / MyFaces
Parece que não consigo disparar um evento quando estou dentro decolumn
dodataTable
. Aqui está minha demonstração simples
<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>
e aqui está meu bean gerenciado
@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);
}
}
Meu problema parece ser que o evento não foi disparado, o que significadelete
nunca seja invocado.
Eu olhei em volta e sei que o Mojarra tem muitos problemas com componentes UIData aninhados, então tentei o Mojarra 2.1.4, ainda não resolvi o problema. Eu tentei o Myfaces 2.1.5, ainda não funciona !!! Isso é um erro do Primefaces? Eu até usoh:panelGroup
como um invólucro paraupdate
mas ainda não funciona.
EDITA: Acontece que op:tree
acima dedataTable
é a causa raiz do evento não disparada ao clicar nocommandButton
. Se eu remover op:tree
então funciona imediatamente. Observe que op:tree
próprio @ funciona muito bem, ao clicar no check-out, evento disparado no meu bean gerenciad