Como recuperar valor do bean com jsf em páginas xhtml

3 respostas
N

bom dia…
estou usando jsf mas não consigo recuperar os valores do bean com páginas xhtml…
estou usando jsf 2.0
meu bean está assim:

package br.com.hrcontrol.modem.backingBean;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name="produto")
@SessionScoped

public class Produto 
{
	private String nome = "Teste";

	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
}

e minha página está assim:

<?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:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" >
	<h:head>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
		<title>Testes</title>
	</h:head>
	<h:body>
		<h:form>
			<h:outputLabel value="#{produto.nome}"></h:outputLabel>
		</h:form>
	</h:body>
</html>

e meu web.xml está assim:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>HRControl</display-name>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
  <context-param>
  	<param-name>javax.faces.PROJECT_STAGE</param-name>
  	<param-value>Development</param-value>
  </context-param>
  <welcome-file-list>
    <welcome-file>index.jsf</welcome-file>
  </welcome-file-list>
</web-app>

eu consigo recuperar com páginas jsp, mas com páginas xhtml não consigo…
obrigado…

3 Respostas

EHS

Na declaração da variavel deixa ela como null, e tenta colocar no construtor da classe ela recebendo algum valor.

public Produto() { nome = "Teste"; }

N

bom dia EHS
ainda assim não funcionou…
aparentemente a UEL não está funcionando na minha página xhtml
muito obrigado…

N

RESOLVIDO…
baixei novamente os arquivos jars mais recentes…

http://javaserverfaces.java.net/

obrigado pela ajuda…

Criado 12 de abril de 2011
Ultima resposta 13 de abr. de 2011
Respostas 3
Participantes 2