Search code examples
javaajaxrichfacesjboss7.x

Ajax is not working with richfaces


I'm trying to use AJAX to change the content of my page and include some other contents, but it just does not work. I tried a lot of different solutions. I need that my menuItem_Cursos call that managed bean changePage and render the component panelGroup_Target. When i try to debug the java it just doesn't get there. Please help.

This is the page

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:a4j="http://richfaces.org/a4j">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>PenSAE</title>
    <f:metadata>
        <f:event listener="#{logon.verificaLogon}" type="preRenderView" />
    </f:metadata>
    <h:outputScript name="common.js" />
</h:head>
<h:body>
    <f:view id="view_Principal">
        <rich:toolbar id="toolbar_Principal" itemSeparator="">
            <rich:menuItem id="menuItem_Cursos" label="Cursos" mode="ajax"
                actionListener="#{principalProfessor.changePage}" render="panelGroup_Target"/>
            <rich:menuItem id="menuItem_Estudos" label="Estudos de Casos"
                value="Estudos de Casos" />
            <rich:dropDownMenu id="dropDownMenu_Acompanhamento"
            label="Acompanhamento" value="Acompanhamento" mode="ajax">
                <rich:menuItem label="Acompanhamento por Estudante" />
                <rich:menuItem label="Acompanhamento por Estudo de Caso" />
            </rich:dropDownMenu>
            <rich:dropDownMenu id="dropDownMenu_Sobre" label="Sobre o Sistema"
                value="Sobre o Sistema">
                <rich:menuItem label="Mapa do Software" />
                <rich:menuItem label="Ajuda" />
            </rich:dropDownMenu>
        </rich:toolbar>
        <h:panelGroup id="panelGroup_Target">
            <rich:panel rendered="#{principalProfessor.page == 'listaCursos'}">
                <ui:include src="#{principalProfessor.page}" />
            </rich:panel>
        </h:panelGroup>
    </f:view>
</h:body>
</html>

And this is my java code:

package magicBeans.professor;

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

import classesBasicas.Curso;
import classesBasicas.Pessoa;

import fachada.Fachada;
/**
 * @author Jesus
 *
 */
@ManagedBean(name="principalProfessor")
@ViewScoped
public class PrincipalProfessorBean {

    @SuppressWarnings("unused")
    private static Fachada fachada;

    private Pessoa usuarioLogado;
    private Curso curso;
    private String page = "";  

    public PrincipalProfessorBean(){

        fachada = Fachada.getInstance();
    }

    /**
     * @return the usuarioLogado
     */
    public Pessoa getUsuarioLogado() {
        return usuarioLogado;
    }

    /**
 * @param usuarioLogado the usuarioLogado to set
     */
    public void setUsuarioLogado(Pessoa usuarioLogado) {
        this.usuarioLogado = usuarioLogado;
    }

    /**
     * @return the curso
     */
    public Curso getCurso() {
        return curso;
    }

    /**
     * @param curso the curso to set
     */
    public void setCurso(Curso curso) {
        this.curso = curso;
    }

    public String getPage() {  
        return page;  
     }  

     public void setPage(String page) {  
        this.page = page;  
     }  

     public void changePage() {  
        page = "listaCursos.xhtml";
        System.out.println("AJAX PEGOU!");
     } 

}

Solution

  • Thanks to chrome (ctrl+shift+j) on chrome, the console told that it needed a form around anything with ajax to work. =]