0

我正在尝试使用 AJAX 来更改我的页面内容并包含一些其他内容,但它不起作用。我尝试了很多不同的解决方案。我需要我的 menuItem_Cursos 调用托管 bean changePage 并呈现组件 panelGroup_Target。当我尝试调试 java 时,它只是没有到达那里。请帮忙。

这是页面

<?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>

这是我的java代码:

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!");
     } 

}
4

1 回答 1

1

多亏了 chrome (ctrl+shift+j) on chrome,控制台告诉它需要一个带有 ajax 的表单才能工作。=]

于 2013-01-11T23:33:31.370 回答