2

I'm having a problem when I include dynamically a page with <ui:include>, the action and actionlistener associated with the <p:commandButton> component is not being invoked. I've tried to remove the tag <h:form> from the included page but the problem persists.What can I do to solve this problem?

The source code:

hello.xhtm (Main Page)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<f:view>    
<h:head>
    <link rel="stylesheet" type="text/css" href="stylesheet.css" />    
    <f:view contentType="text/html" />
</h:head>
<h:body>
    <h:form id="helloForm">
        <p:growl id="messages" />
        <p:panelGrid id="panelGridPrincipal" styleClass="panelGridPrincipal">
            <p:row>
                <p:column colspan="2">
                    <div style="width: 100%; height: 25px; padding-left: 230px;">
                        <p:commandButton id="botao1" value="Bookmark" styleClass="button"/>
                        <p:commandButton id="botao2" value="Bookmark2" styleClass="button"
                            actionListener="#{mainBean.renderMenuVendas}" update="panel" >
                            <f:setPropertyActionListener value="2" target="#{mainBean.menuType}" />  
                        </p:commandButton>
                    </div>
                </p:column>
            </p:row>
            <p:row>
                <p:column id="column2" style="width:200px;background-color: #5A5858;">
                    <h:panelGrid id="panel" styleClass="panelGridMenu" columns="1">
                        <p:menu id="dynamicMenu" model="#{mainBean.sideMenu}" rendered="#{mainBean.showMenuVendas}" style="width:189px;margin-right:100%;"/>
                        <p:spacer width="50px" height="700px" />
                    </h:panelGrid>
                </p:column>
                    <p:column style="background-color: white">
                        <p:panelGrid style="border:1px;">
                            <p:row>
                                <p:column>
                                    <p:outputPanel id="outputPanelConteudo">
                                        <ui:include src="#{mainBean.paginaAtual}" />
                                    </p:outputPanel>
                                </p:column>
                            </p:row>
                            <p:row/>
                        </p:panelGrid>
                    </p:column>
                </p:row>
        </p:panelGrid>
    </h:form>
</h:body>
</f:view>
</html>

pagina1.xhtml (Included Page)

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
    <p:dataTable id="avioes" var="aviao" value="#{listaAvioesBean.aviao}"
        rowKey="#{aviao.numeroSerie}"
        selection="#{listaAvioesBean.selectedAviao}" selectionMode="single"
        style="width:500px">

        <p:column style="width:75px">
            <f:facet name="header">
                <h:outputText value="Numero de Serie" />
            </f:facet>
            <h:outputText value="#{aviao.numeroSerie}" />
        </p:column>

        <p:column style="width:100px">
            <f:facet name="header">
                <h:outputText value="Marca" />
            </f:facet>
            <h:outputText value="#{aviao.marca}" />
        </p:column>

        <p:column style="width:75px">
            <f:facet name="header">
                <h:outputText value="Modelo" />
            </f:facet>
            <h:outputText value="#{aviao.modelo}" />
        </p:column>

        <p:column style="width:75px">
            <p:commandButton id="insertAviao" value="Inserir" title="Visualizar">
                <f:setPropertyActionListener value="#{aviao}"
                    target="#{listaAvioesBean.selectedAviao}" />
            </p:commandButton>
                 <!--THESE ACTION DOESN'T CALL THE BEAN METHOD!!!  -->
                <p:commandButton id="removerAviao" style="width:50px" value="P"
                    title="Deletar" action="#{listaAvioesBean.removerAviao}"
                    update=":helloForm:outputPanelConteudo">
                    <f:setPropertyActionListener value="#{aviao}"
                        target="#{listaAvioesBean.selectedAviao}" />
                </p:commandButton>
        </p:column>
    </p:dataTable>
</ui:composition>

Managed bean (ListaAvioesBean.java)

package br.com.erp.beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;

import br.com.erp.object.Aviao;

@ManagedBean(name="listaAvioesBean")
@ViewScoped
public class ListaAvioesBean implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 8076960891132613195L;
    private Aviao selectedAviao;
    private List<Aviao> aviao;

    public ListaAvioesBean(){

        aviao = new ArrayList<Aviao>();
        System.out.println("ListaAvioesBean Criado!");

    }

    @PostConstruct
    public void init(){

        System.out.println("Iniciando o bean!");
        populateListAvioes();   
    }

    public void executa(){

        System.out.println("Executou");

    }


    private void populateListAvioes(){

        Aviao av1 = new Aviao();
        av1.setMarca("Marca1");
        av1.setModelo("M1");
        av1.setNumeroSerie("1234");
        aviao.add(av1);
        av1 = new Aviao();
        av1.setMarca("Marca2");
        av1.setModelo("M2");
        av1.setNumeroSerie("1111");
        aviao.add(av1);
        av1 = new Aviao();
        av1.setMarca("Marca3");
        av1.setModelo("M3");
        av1.setNumeroSerie("4321");
        aviao.add(av1);

    }

    public Aviao getSelectedAviao() {
        return selectedAviao;
    }

    public void setSelectedAviao(Aviao selectedAviao) {
        this.selectedAviao = selectedAviao;
    }

    public List<Aviao> getAviao() {
        return aviao;
    }

    public void setAviao(List<Aviao> aviao) {
        this.aviao = aviao;
    }


    public void removerAviao(){

        boolean removeu = aviao.remove(selectedAviao);

        if(removeu)
            System.out.println("Avião removido com sucesso");

    }

    public void executa(ActionEvent e){

        System.out.println();

    }


}
  • You have nested forms, remove the inner form inside of `pagina1`. Clean and build your project, restart the application server and try again. – Luiggi Mendoza Aug 14 '12 at 14:36
  • Hello!Thanks for the reply.I just removed but the problem persists any other idea? – user1598186 Aug 14 '12 at 14:45
  • are you sure it's not executing the backing bean? it looks like you're trying to twiddle the "rendered" attribute via ajax, and afaik, that's not going to give you the results you want (i had a similar issue with openfaces and a menu setup i was trying out). you might want instead to look at either twiddling the "display" attribute via javascript or reworking the hide/show aspect of your menu (id="panel"). – him Aug 14 '12 at 23:44
  • Hello!I've solved the problem!Actually I've give up of include dinamically the page and now I'm using variables in the managed bean to render the specific code fragment when a menuitem is chosen. I think is a solution similar as yours. Thanks any way!! – user1598186 Aug 15 '12 at 00:52

0 Answers0