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:
[code]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");
}
}[/code]
Web.xml :
[code]<?xml version="1.0"?>
TrabComJSF
javax.faces.STATE_SAVING_METHOD
server
com.sun.faces.disableVersionTracking
true
com.sun.faces.config.ConfigureListener
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:
[code]<%@ taglib uri=“http://java.sun.com/jsf/html” prefix=“h” %>
<%@ taglib uri=“http://java.sun.com/jsf/core” prefix=“f” %>
<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>
[/code]
boasVindas.jsp:
[code]<%@ taglib uri=“http://java.sun.com/jsf/html” prefix=“h” %>
<%@ taglib uri=“http://java.sun.com/jsf/core” prefix=“f” %>
[/code]
O problema acontece, após clicar no botão enviar da página trabComJSF.jsp.
O erro é o seguinte:
[i]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.[/i]
Alguém tem alguma idéia do que seja o problema?
Agradeço desde já.