I'm trying to make the following code work in IE 8 with no result (though it works in Google chrome fine):
xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
</h:head>
<h:body>
<h:form id="form">
<p:dataTable id="eventsDT" var="answer" value="#{verify.answers}" rowKey="#{answer.id}" selectionMode="single" >
<p:ajax event="rowSelect" listener="#{verify.onRowSelectTest}" />
<p:column headerText="Id">
<h:outputText value="#{answer.id}" />
</p:column>
<p:column headerText="Text">
<h:outputText value="#{answer.text}" />
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>
Answer.java:
package ru.trust.appVerification;
public class Answer {
private int id;
private String text = "Undefined";
public Answer(int id, String text) {
this.id = id;
this.text = text;
}
public int getId() {
return id;
}
public String getText() {
return text;
}
public void setId(int id) {
this.id = id;
}
public void setText(String text) {
this.text = text;
}
}
Verify.java
package ru.trust.appVerification;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.*;
import java.util.stream.*;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.AjaxBehaviorEvent;
import org.primefaces.event.SelectEvent;
#ManagedBean
#ViewScoped
public class Verify implements Serializable {
public List<Answer> getAnswers() {
List<Answer> answers = new ArrayList<Answer>();
answers.add(new Answer(1, "Yes"));
answers.add( new Answer(2, "No"));
return answers;
}
public void onRowSelectTest(SelectEvent event) {
Answer answer = (Answer)event.getObject();
}
}
Is anything wrong in my code or Internet Explorer 8 does not support it at all?
Try adding this at the top of your xhtml :
<?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">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<f:facet name="first">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
</f:facet>
// other head code goes here
</h:head>
in place of :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
</h:head>
I had a similar issue.Adding this worked fine for me.
Related
I am trying to get a static variable in my JSF page.
I followed instructions on this post. I am able to get the variables using the Primefaces extension, however, I am not getting anything in the xhtml when doing the following.
I have a constants file:
public class Test {
public static final String NAME = "EL Test";
}
And following the post by balusC, I added an application scoped bean (however, this is being called with every request):
import java.lang.reflect.Field;
import javax.annotation.PostConstruct;
import javax.el.ELContextEvent;
import javax.el.ELContextListener;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
#ManagedBean(eager = true)
#ApplicationScoped
public class Config {
#PostConstruct
public void init() {
FacesContext.getCurrentInstance().getApplication().addELContextListener(new ELContextListener() {
#Override
public void contextCreated(ELContextEvent event) {
event.getELContext().getImportHandler().importClass("my.package.constants.Test");
Class<?> clazz = event.getELContext().getImportHandler().resolveClass("Test");
for (Field field : clazz.getFields()) {
System.out.println(field.getName());
}
System.out.println("clazz = " + clazz);
System.out.println(clazz.getPackage());
}
});
}
}
And my xhtml page:
<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta charset="utf-8"></meta>
<meta http-equiv="X-UA-Compatible" content="IE=edge"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1"></meta>
</h:head>
<h:body>
<h:outputText value="#{Test}"></h:outputText>
<h:outputText value="#{Test.NAME}"></h:outputText>
</h:body>
</html>
Is there anything I am missing?
p:importConstants was added in PrimeFaces 6.x.
XHTML:
<p:importConstants type="com.example.Constants" var="Constants" />
<h:outputText value="#{Constants.TEST}" />
Java:
package com.example;
public class Constants {
public final static String TEST = "Imported Constant";
}
JSF 2.3 supports referencing static variables in EL using the f:importConstants tag.
Your constants file
public class Test {
public static final String NAME = "EL Test";
}
can be imported in the view by adding the following metadata.
<f:metadata>
<f:importConstants type="mypackage.Test" />
</f:metadata>
And then be referenced using EL.
#{Test.NAME}
So your view becomes:
<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<f:metadata>
<f:importConstants type="mypackage.Test" />
</f:metadata>
<h:head>
<meta charset="utf-8"></meta>
<meta http-equiv="X-UA-Compatible" content="IE=edge"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1"> </meta>
</h:head>
<h:body>
<h:outputText value="#{Test.NAME}"></h:outputText>
</h:body>
</html>
Source: Arjan Tijms' Weblog.
You can use o:importConstants by omnifaces for that
For example:
public class Foo {
public static final String FOO1 = "foo1";
public static final String FOO2 = "foo2";
}
public interface Bar {
public String BAR1 = "bar1";
public String BAR2 = "bar2";
}
public enum Baz {
BAZ1, BAZ2;
}
The constant field values of the above types can be mapped into the request scope as follows:
<o:importConstants type="com.example.Foo" />
<o:importConstants type="com.example.Bar" />
<o:importConstants type="com.example.Baz" var="Bazzz" />
...
#{Foo.FOO1}, #{Foo.FOO2}, #{Bar.BAR1}, #{Bar.BAR2}, #{Bazzz.BAZ1}, #{Bazzz.BAZ2}
As I see you're using JSF 2, you could go with the Omnifaces library:
public class Test {
public static final String NAME = "EL Test";
}
Then in the facelet:
<o:importConstants type="com.example.Test " />
#{Test.NAME}
Otherwise, if you want to avoid using third party libraries, use an #ApplicationScoped managed bean with a getter for this aim:
#ManagedBean
#ApplicationScoped
public class Test{
public static final String name = "EL Test";
public String getName(){
return name;
}
}
Which you can reference with:
#{test.name}
See also:
The importConstants tag
I'm having trouble understanding why a action method on my ConversationScope'd bean doesnt fire. The bean is:
package org.work;
import java.io.Serializable;
import javax.enterprise.context.ConversationScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Named;
#Named
#ConversationScoped
public class NewClass implements Serializable {
private static final long serialVersionUID = 6470665657635110586L;
private boolean b1;
public boolean isB1() {
return b1;
}
public void setB1(boolean b1) {
this.b1 = b1;
}
public void preRenderView(ComponentSystemEvent evt) {
}
public String peformAction() {
return null;
}
}
and my XHTML is:
<?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">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:view>
<h:head>
</h:head>
<f:metadata>
<f:viewParam name="b1"
value="#{newClass.b1}" />
<f:event type="preRenderView"
listener="#{newClass.preRenderView}"/>
</f:metadata>
<h:body>
<h:form>
<h:commandLink action="#{newClass.setB1(!newClass.b1)}"
style="background-color: #{newClass.b1 ? 'darkorchid' : 'aquamarine'};"
value="btn3"/>
<h:panelGrid rendered="#{newClass.b1}"
columns="1">
<h:commandLink value="edit"
action="#{newClass.peformAction()}" />
</h:panelGrid>
</h:form>
</h:body>
</f:view>
</html>
The performAction() method is not fired after I press the commandLink that should invert the boolean making the other commandLink rendered. When debugging I can see that the boolean is set to true, but it seems to me the "rendered" attribute is evaluated before the viewparams is set. Is this true?
The example works fine with #ManagedBean and #javax.faces.bean.ViewScoped.
I think that you don't have long-running conversation. You could read more information on this site: http://docs.oracle.com/javaee/6/api/javax/enterprise/context/ConversationScoped.html
If you have transient conversation this bean is recreated after every request
I have the following page xhtml where i have to get some values for populate a DB table. The problem are the selection menu that don't work. Actually, the values of the selections are chosen from the database and are displayed but the values aren't taken when i use the button:
<!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">
<h:head>
<title>Add a Default Package</title>
</h:head>
<h:body>
<h:form>
<p:panel header="DefaultPackage Form">
<h:panelGrid columns="3" id="regGrid">
<h:outputLabel for="Name">Name:</h:outputLabel>
<p:inputText id="Name" value="#{addDefaultPackageBean.defpackDTO.name}" />
<p:message for="Name" />
<h:outputLabel for="location">Location:</h:outputLabel>
<p:inputText id="location" value="#{addDefaultPackageBean.defpackDTO.location}" />
<p:message for="location" />
<h:selectOneMenu value="#{addDefaultPackageBean.nameFlies}">
<f:selectItems value="#{addDefaultPackageBean.elelisfly}" var="ElementDTO" itemValue="#{ElementDTO.location}" itemLabel="#{ElementDTO.location}"/>
</h:selectOneMenu>
<h:selectOneMenu value="#{addDefaultPackageBean.nameHotels}">
<f:selectItems value="#{addDefaultPackageBean.elelishotel}" var="ElementDTO" itemValue="#{ElementDTO.location}" itemLabel="#{ElementDTO.location}"/>
</h:selectOneMenu>
</h:panelGrid>
<p:commandButton value="Add" update="regGrid" action="#{addDefaultPackageBean.add()}" />
</p:panel>
</h:form>
</h:body>
</html>
The image displayed is:
The bean page:
package beans;
import java.util.ArrayList;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import elementManagement.ElementMgr;
import elementManagementDTO.ElementDTO;
import DefaultPackageManagement.DefaultPackageMgr;
import DefaultPackageManagementDTO.DefaultPackageDTO;
#ManagedBean(name="addDefaultPackageBean") //come viene richiamato
#RequestScoped
public class AddDefaultPackageBean {
#EJB
private DefaultPackageMgr defpackMgr;
private DefaultPackageDTO defpackDTO;
private ArrayList<ElementDTO> elelisfly;
private ArrayList<ElementDTO> elelishotel;
private String nameFlies;
private String nameHotels;
#EJB
private ElementMgr elemMgr;
public AddDefaultPackageBean() {
defpackDTO = new DefaultPackageDTO();
defpackDTO.setElem(new ArrayList<ElementDTO>());
}
#PostConstruct
public void init()
{
setElelisfly(elemMgr.getAllFlights());
setElelishotel(elemMgr.getAllHotels());
}
public String add() {
this.AssignElemFlyFromSelection();
this.AssignElemHotelFromSelection();
defpackMgr.save(defpackDTO);
return "/employee/index?faces-redirect=true";
}
public DefaultPackageDTO getDefpackDTO() {
return defpackDTO;
}
public void setDefpackDTO(DefaultPackageDTO defpackDTO) {
this.defpackDTO = defpackDTO;
}
public ArrayList<ElementDTO> getElelisfly() {
return elelisfly;
}
public void setElelisfly(ArrayList<ElementDTO> elelisfly) {
this.elelisfly = elelisfly;
}
public ArrayList<ElementDTO> getElelishotel() {
return elelishotel;
}
public void setElelishotel(ArrayList<ElementDTO> elelishotel) {
this.elelishotel = elelishotel;
}
public String getNameFlies() {
return nameFlies;
}
public void setNameFlies(String nameFlies) {
this.nameFlies = nameFlies;
}
public String getNameHotels() {
return nameHotels;
}
public void setNameHotels(String nameHotels) {
this.nameHotels = nameHotels;
}
private void AssignElemFlyFromSelection()
{
for (ElementDTO elem:this.elelisfly)
{
if(elem.getLocation()==this.nameFlies)
{
this.defpackDTO.getElem().add(elem);
}
}
}
private void AssignElemHotelFromSelection()
{
for (ElementDTO elem:this.elelishotel)
{
if(elem.getLocation()==this.nameHotels)
{
this.defpackDTO.getElem().add(elem);
}
}
}
}
Thank you for the help!
You're comparing Java String objects using == operator instead of .equals() method. That causes a comparison between Object references to be performed, instead of implemented String comparison.
elem.getLocation()==this.nameFlies
and
elem.getLocation()==this.nameHotels
Change them for String#equals().
See also:
Java String.equals versus ==
Add process to your commandobutton.
Like this:
<p:commandButton process="#form" value="Add" update="regGrid" action="#{addDefaultPackageBean.add()}" />
I am trying to update a duration (difference of two dates being captured by . When I add the fireDrillEvacTime to the rendering of the following stack trace dump:
JBWEB000309: type JBWEB000066: Exception report
JBWEB000068: message <f:ajax> contains an unknown id 'fireDrillStartTime,fireDrillEvacTime' - cannot locate it in the context of the component fireDrillStartTime
JBWEB000069: description JBWEB000145: The server encountered an internal error that prevented it from fulfilling this request.
JBWEB000070: exception
javax.servlet.ServletException: <f:ajax> contains an unknown id 'fireDrillStartTime,fireDrillEvacTime' - cannot locate it in the context of the component fireDrillStartTime
javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
org.monarchnc.filter.LoginFilter.doFilter(LoginFilter.java:41)
JBWEB000071: root cause
javax.faces.FacesException: <f:ajax> contains an unknown id 'fireDrillStartTime,fireDrillEvacTime' - cannot locate it in the context of the component fireDrillStartTime
com.sun.faces.renderkit.html_basic.AjaxBehaviorRenderer.getResolvedId(AjaxBehaviorRenderer.java:289)
com.sun.faces.renderkit.html_basic.AjaxBehaviorRenderer.appendIds(AjaxBehaviorRenderer.java:276)
com.sun.faces.renderkit.html_basic.AjaxBehaviorRenderer.buildAjaxCommand(AjaxBehaviorRenderer.java:218)
com.sun.faces.renderkit.html_basic.AjaxBehaviorRenderer.getScript(AjaxBehaviorRenderer.java:88)
javax.faces.component.behavior.ClientBehaviorBase.getScript(ClientBehaviorBase.java:103)
Here is my xhtml file:
<h:outputLabel for="fireDrillStartTime" value="Fire Drill Start Time:"/>
<rich:calendar value="#{fireDrillBean.fireDrill.fireDrillStartTime}" id="fireDrillStartTime"
popup="true" datePattern="yyyy-MM-dd HH:mm:ss"
enableManualInput="true" required="true"
showApplyButton="true" cellWidth="24px" cellHeight="22px" style="width:200px">
<f:ajax event="change" execute="#this" bypassUpdates="#{true}" render="fireDrillStartTime,fireDrillEndTime"/>
</rich:calendar>
<h:outputText value="*"/>
<h:outputLabel for="fireDrillEndTime" value="Fire Drill End Time:"/>
<rich:calendar value="#{fireDrillBean.fireDrill.fireDrillEndTime}" id="fireDrillEndTime"
popup="true" datePattern="yyyy-MM-dd HH:mm:ss"
enableManualInput="true" required="true"
showApplyButton="true" cellWidth="24px" cellHeight="22px" style="width:200px">
<f:ajax event="change" execute="#this" bypassUpdates="#{true}" render="fireDrillEndTime,fireDrillEndTime"/>
</rich:calendar>
<h:outputText value="*"/>
<h:outputLabel for="fireDrillEvacTime" value="Fire Drill Evac Time:"/>
<h:outputText id="fireDrillEvacTime" value="#{fireDrillBean.evacDuration}" style="width: 175px;"/>
<h:outputText value="" />
Here is the setter/getter:
public Long getEvacDuration() {
return evacDuration;
}
public void setEvacDuration(long evacDuration) throws Exception{
try{
if (this.fireDrill.getFireDrillStartTime() != null && this.fireDrill.getFireDrillEndTime() != null){
evacDuration= fireDrill.getFireDrillStartTime().getTime() - fireDrill.getFireDrillEndTime().getTime();
evacDuration = timeUnit.convert(evacDuration,TimeUnit.SECONDS);
this.fireDrill.setEvacuationDuration(evacDuration);
}
}
catch (Exception up) {
throw up;
}
this.evacDuration=evacDuration;
}
I am new to this, and have searched on how to calculate the date, but having a hard time with figuring how to get a rich:calendar to execute an ajax call when either of the dates are changed to rerender the fireEvacTimeTime without having to click a calculation button. What am I doing wrong?
Hej Azulitabijou,
i wrote a small example for you. It is working, but you'll have to adapt it to your needs.
I left out all the patterns and evaluations..
The Controller Class
package de.professional_webworkx.so.controller;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.enterprise.inject.Model;
import javax.enterprise.inject.Produces;
import javax.faces.context.FacesContext;
import javax.faces.event.AjaxBehaviorEvent;
import javax.inject.Inject;
import javax.inject.Named;
#Model
public class FireCalendarController {
#Inject
FacesContext context;
private Date startDate;
private Date endDate;
private long duration;
#Produces
#Named
public Date getStartDate() {
Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "MSG");
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
#Produces
#Named
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
#Produces
#Named
public long getDuration() {
return duration;
}
public void setDuration(long duration) {
this.duration = duration;
}
public void doSomething() {
duration = endDate.getTime()-startDate.getTime();
Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "Start was " + startDate);
}
}
UPDATE
create your own calendar component like this and place it under webapp/resources/emcomp/calendar.xhtml:
<!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:rich="http://richfaces.org/rich"
xmlns:composite="http://java.sun.com/jsf/composite">
<!-- INTERFACE -->
<composite:interface>
<composite:attribute name="date" />
<composite:clientBehavior name="date_change" event="change" targets="#{cc.id}"/>
</composite:interface>
<!-- IMPLEMENTATION -->
<composite:implementation>
<h:panelGrid columns="2">
<h:outputText value="Startdatum" />
<rich:calendar id="#{cc.id}" value="#{cc.attrs.date}" datePattern="dd.MM.yyyy"></rich:calendar>
</h:panelGrid>
</composite:implementation>
</html>
And use your calendar-component like this:
<!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:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:em="http://java.sun.com/jsf/composite/emcomp">
<h:head></h:head>
<h:body>
<rich:panel>
<f:facet name="header">
fireDrill at SO ;9
</f:facet>
<h:form>
<h:panelGrid columns="2">
<h:outputText value="Startdate:" />
<!--
<rich:calendar value="#{fireCalendarController.startDate}"></rich:calendar>
-->
<em:calendar id="start" date="#{fireCalendarController.startDate}">
</em:calendar>
<em:calendar id="end" date="#{fireCalendarController.endDate}">
<a4j:ajax event="date_change" execute="start,end" render="duration"/>
</em:calendar>
<h:outputText value="Duration" />
<h:outputText id="duration" value="#{fireCalendarController.duration}" />
</h:panelGrid>
</h:form>
</rich:panel>
</h:body>
</html>
I hope this will help you to go on working.
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!");
}
}
Thanks to chrome (ctrl+shift+j) on chrome, the console told that it needed a form around anything with ajax to work. =]