我正在尝试使用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!");
}
}
答案 0 :(得分:1)
感谢Chrome上的chrome(ctrl + shift + j),控制台告诉它需要一个带有ajax的表单。 =]