Problema JSF

2 respostas
F

Olá Galera, estou começando a trabalhar com JSF e tive um probleminha e gostaria que vocês me dessem uma ajuda.

Segue meu código:

Entidade:
package br.com.integrator;

import java.io.Serializable;

public class MeuBean {
	private String nome;

	public String getNome() {
		return nome;
	}

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

Controller:

package br.com.integrator.controller;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import br.com.integrator.MeuBean;

public class Controle  {
	private MeuBean meuBean;
	
	public Controle() {
		meuBean = new MeuBean();
	}

	public MeuBean getMeuBean() {
		return meuBean;
	}

	public void setMeuBean(MeuBean meuBean) {
		this.meuBean = meuBean;
	}
	
	public String acao() {
		boolean sucesso = true;
		FacesContext context = FacesContext.getCurrentInstance();
		if (meuBean.getNome()!= null) {
			for ( int i = 0;i<meuBean.getNome().length();i++) {
				char c = meuBean.getNome().charAt(i);
				if(!Character.isLetter(c)&&!Character.isSpace(c)) {
					String msg = "Digite Somente caracteres alfabéticos";
					FacesMessage message = new FacesMessage(msg);
					context.addMessage("formulario", message);
					sucesso = false;
					break;
				}
			}
		} else {
			sucesso = false;
		}
		return (sucesso ? "sucesso" : "falha");
	}
}

Web.xml :

<?xml version="1.0"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <display-name>TrabComJSF</display-name>
 <context-param>
  <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
  <param-value>server</param-value>
 </context-param>
 <context-param>   
  <param-name>com.sun.faces.disableVersionTracking</param-name>   
  <param-value>true</param-value>   
</context-param>  
 <listener>
  <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
 </listener>
 <!-- Faces Servlet -->
 <servlet>
  <servlet-name>Faces Servlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <!-- Faces Servlet Mapping -->
 <servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.jsf</url-pattern>
 </servlet-mapping>
 <login-config>
  <auth-method>BASIC</auth-method>
 </login-config>
</web-app>

Faces-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xi="http://www.w3.org/2001/XInclude"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
 <managed-bean>
  <managed-bean-name>controle</managed-bean-name>
  <managed-bean-class>br.com.integrator.controller.Controle</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
 </managed-bean>
 <navigation-rule>
  <from-view-id>/trabComJSF.jsp</from-view-id>
  <navigation-case>
   <from-outcome>sucesso</from-outcome>
   <to-view-id>/boasVindas.jsp</to-view-id>
  </navigation-case>
  <navigation-case>
   <from-outcome>falha</from-outcome>
   <to-view-id>/trabComJSF.jsp</to-view-id>
  </navigation-case>
 </navigation-rule>
</faces-config>

trabComJSF.jsp:

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>


	<head>
		<title></title>
	</head>
	<body>
		<f:view>
			<h:form id="formulario">
				Digite seu nome:
				<h:inputText id="nome" value="#{controle.meuBean.nome}" required="true"/>
				<h:commandButton action="#{controle.acao}" value="Enviar" id="submit"/>
				<br/>
				<h:messages/>
			</h:form>
		</f:view>
	</body>	
</html>

boasVindas.jsp:

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>
	<head>
		<title></title>
	</head>
	<body>
		<f:view>
			Olá <h:outputText value="#{MeuBean.nome}" /> <br/>
		</f:view>
	</body>	
</html>

O problema acontece, após clicar no botão enviar da página trabComJSF.jsp.
O erro é o seguinte:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: viewId:/trabComJSF.jsf - View /trabComJSF.jsf could not be restored.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:270)

root cause

javax.faces.application.ViewExpiredException: viewId:/trabComJSF.jsf - View /trabComJSF.jsf could not be restored.
com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:186)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:104)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.26 logs.

Alguém tem alguma idéia do que seja o problema?

Agradeço desde já.

2 Respostas

Mr_Arthur

Não está no forum errado não?
Frameworks e Bibliotecas brasileiros

ViniGodoy

Não duplique tópicos. Na dúvida sobre qual fórum abrir, abra o tópico num só e nós da moderação o moveremos, se for o caso.

Esse tópico será trancado. Outros usuários podem acompanhar por:
http://www.guj.com.br/posts/list/221612.java

Criado 15 de outubro de 2010
Ultima resposta 15 de out. de 2010
Respostas 2
Participantes 3