JSF....javax.servlet.ServletException: Base is null: cadastroBean

Olá,

não consigo visualizar onde está dando erro.

Se alguem puder me ajudar agradeceria.

abs

<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	

	<!-- JavaServer Faces -->
	
	<display-name>Daca</display-name>


    <description>
        Aplicação Exemplo DACA
    </description>    

    <welcome-file-list>
        
	    <welcome-file>index.jsf</welcome-file>
    </welcome-file-list>    

	<!-- JavaServer Faces -->

    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>

	<context-param>

    	<param-name>javax.faces.CONFIG_FILES</param-name>
    	<param-value>/WEB-INF/faces-config.xml</param-value>
  	</context-param>

    <context-param>
        <param-name>com.sun.faces.validateXml</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>
	
	
</web-app>
<faces-config>


    <application>

      <locale-config>
        <default-locale>br</default-locale>
      </locale-config>

      <message-bundle>daca.bundle.Messages</message-bundle>
    
  </application>
  
	
	  <managed-bean>
	    <description>
	    </description>
	    <managed-bean-name>cadastroBean</managed-bean-name>
	    <managed-bean-class>daca.bean.Usuario</managed-bean-class>
	    <managed-bean-scope>session</managed-bean-scope>
	  </managed-bean>
	  
   <navigation-rule>

    <from-view-id>*</from-view-id>
	    <navigation-case>
	        <description>
	        </description>
	        <from-outcome>sucesso</from-outcome>
	        <to-view-id>/index.jsp</to-view-id>
	    </navigation-case>    
    </navigation-rule>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"  %>
<%@ taglib  uri="http://java.sun.com/jsf/html" prefix="h" %>
<html>
<f:view>

	<body>
		<h:form>			
			<table>
					<tr>
						<td>
							<h:outputText value="Login"/>
						</td>
						<td>
							<h:inputText id="login"  value="#{cadastroBean.login}" required="true"/>
							<h:message for="login"/>
						</td>
					</tr>
					<tr>
						<td>
							<h:outputText value="Senha"/>
						</td>
						<td>
							<h:inputSecret id="senha" value="#{cadastroBean.senha}" required="true"/> 
							<h:message for="senha"/>							
						</td>
					</tr>			
					<tr>
						<td>
							<h:outputText value="E-mail" />
						</td>
						<td>
							<h:inputText id="mail"  value="#{cadastroBean.mail}" required="true"/> 
							<h:message for="mail"/>							
						</td>
					</tr>			
					
				<tr>
					<td>
						<h:commandButton action="#{cadastroBean.save}" value="Enviar Dados"/> 
					</td>
				</tr>			
			</table>
		</h:form>	
		
		<h:form id="removeUsuario">	
		
			
			<h:dataTable  value="#{cadastroBean.lista}" border="1" var="usuario">

				<h:column>
					<f:facet name="header">
						<h:outputText value="Login"/>
					</f:facet>
					<h:outputText value="#{usuario.login}"></h:outputText>
	
				<f:facet name="footer">
						<h:outputText value="Login"/>
					</f:facet>
					
				</h:column>
				
				<h:column>
					<f:facet name="header">
						<h:outputText value="E-mail"/>
					</f:facet>
					<h:outputText value="#{usuario.mail}"></h:outputText>
					<f:facet name="footer">
						<h:outputText value="E-mail"/>
					</f:facet>
				</h:column>
				<h:column>
					<f:facet name="header">
						<h:outputText value="Ação"/>
					</f:facet>
					<h:commandLink value="#{usuario.id}" actionListener="#{cadastroBean.remove}">
					
						<h:outputText value="Excluir"></h:outputText>
					</h:commandLink>
					<f:facet name="footer">
						<h:outputText value="Ação"/>
					</f:facet>				
				</h:column>										
			</h:dataTable>
		</h:form>
		
		
		
	<body>
</f:view>
</html>
type Exception report

message

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

exception

javax.servlet.ServletException: Base is null: cadastroBean
	javax.faces.webapp.FacesServlet.service(FacesServlet.java:202)

root cause

javax.faces.el.PropertyNotFoundException: Base is null: cadastroBean
	org.apache.myfaces.el.ValueBindingImpl.resolveToBaseAndProperty(ValueBindingImpl.java:463)
	org.apache.myfaces.el.ValueBindingImpl.getType(ValueBindingImpl.java:175)
	com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:111)
	javax.faces.component.UIInput.getConvertedValue(UIInput.java:713)
	javax.faces.component.UIInput.validate(UIInput.java:638)
	javax.faces.component.UIInput.executeValidate(UIInput.java:849)
	javax.faces.component.UIInput.processValidators(UIInput.java:412)
	javax.faces.component.UIForm.processValidators(UIForm.java:170)
	javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:912)
	javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:342)
	org.apache.myfaces.lifecycle.ProcessValidationsExecutor.execute(ProcessValidationsExecutor.java:32)
	org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
	org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
	javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.25 logs.
public class Usuario {	

	
	private int id ;
	private String login="";
	private String senha="";
	private String mail="";

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getSenha() {
		return senha;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}

	public String getMail() {
		return mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	
	public String save() {		
		try {
			
		    Connection cn = Conexao.obterConexao();
	        PreparedStatement statement = null;
		
			statement = cn.prepareStatement("insert into usuario (login,senha,mail) values  (?,?,?)");
			statement.setString(1,login);
			statement.setString(2,senha);
			statement.setString(3,mail);
			statement.executeUpdate();
			cn.close();
			return "sucesso";
		} catch (SQLException e) {
			e.printStackTrace();
			return "falha";
		}		
	}

	/* (non-Javadoc)
	 * @see daca.service.PersistenteIF#remove(java.lang.String)
	 */
	public void remove(String id) {
		try {			
			Connection cn = Conexao.obterConexao();
	        PreparedStatement statement = null;
			statement = cn.prepareStatement("delete from usuario where id=?");
			statement.setString(1,id);			
			statement.execute();
			cn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}		
	}

	/* (non-Javadoc)
	 * @see daca.service.PersistenteIF#selectTodos()
	 */
		
	
	
	/* (non-Javadoc)
	 * @see daca.service.PersistenteIF#selectTodos()
	 */
	
/*	
	public List getLista() {
		Connection cn = Conexao.obterConexao();
		List lista = new ArrayList();
		try {			

			Usuario u = new Usuario();
			u.setId(10);
			u.setLogin("usuario");				
			u.setSenha("senha");
			u.setMail("a@a.com.br");
			lista.add(u);

			
			ResultSet rs = cn.createStatement().executeQuery("select * from usuario");
			while(rs.next()){
				Usuario u = new Usuario();
				u.setId(rs.getInt(1));
				u.setLogin(rs.getString(2));				
				u.setSenha(rs.getString(3));
				u.setMail(rs.getString(4));
				lista.add(u);
			}
			cn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}		
		return lista;
	}

	*/
	 public ResultSet getLista(){
	    	ResultSet rs = null;
	    	Connection cn = Conexao.obterConexao();
	        PreparedStatement pst = null;
	        try {
	            pst = cn.prepareStatement("select * from usuario");
	            rs = pst.executeQuery();
	            cn.close();
	        } catch (SQLException e) {
	        }
	    	return rs;
	    }
}


Esse erro ocorre quando?

Quando abre a página ou quando vc clica em algum botão?

quando digito na tela os campos e clico no botão para

incluir.

Debuga o código e verifica qual a linha do método save está dando erro.

Olá fiz os breakpoint nas classes mas não entra na classe

e vai para o erro …

Socorro…alguém me ajuda…abs

EVERE: Both MyFaces and the RI are on your classpath. Please make sure to use only one of the two JSF-implementations.
22/02/2008 12:08:14 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
javax.faces.el.PropertyNotFoundException: Base is null: cadastro
	at org.apache.myfaces.el.ValueBindingImpl.resolveToBaseAndProperty(ValueBindingImpl.java:463)
	at org.apache.myfaces.el.ValueBindingImpl.getType(ValueBindingImpl.java:175)
	at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:111)
	at javax.faces.component.UIInput.getConvertedValue(UIInput.java:713)
	at javax.faces.component.UIInput.validate(UIInput.java:638)
	at javax.faces.component.UIInput.executeValidate(UIInput.java:849)
	at javax.faces.component.UIInput.processValidators(UIInput.java:412)
	at javax.faces.component.UIForm.processValidators(UIForm.java:170)
	at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:912)
	at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:342)
	at org.apache.myfaces.lifecycle.ProcessValidationsExecutor.execute(ProcessValidationsExecutor.java:32)
	at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
	at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
	at java.lang.Thread.run(Thread.java:595)

Esse último post clareou as dúvidas.

EVERE: Both MyFaces and the RI are on your classpath. Please make sure to use only one of the two JSF-implementations.  

Parece que vc colocaou os jar’s do MyFaces do SUN-RI no seu classpath, porém os dois são implementações do Jsf e vc deve utilizar apenas um.
O próprio erro já diz.

obrigado pelo retorno…

enqto rodava no eclipse com tomcat…dava esse erro

qdo gerei o war e fui rodar no servidor não deu mas esse erro.

abs

mais uma dica que fiz :

  • pois no eclipse eu tinha varios projetos uns com jsf outros com myfaces

  • criei outra workspace só pra esse projeto que estava fazendo

  • começou a rodar sem erros

  • gerei o war e rodou no servidor de aplicação sem erros