JSF...useo comando commandLink valor com zero

Olá pessoal,

uma duvida criei um link em uma pagina jsp

onde recebo o numero do usuario para depois

se for deletar essa linha passo esse numero

mas quando debugei na classe o numero é sempre

zero.

alguem poderia me ajudar onde estou errando…

abs

 <h:commandLink value="#{usuario.id}" action="#{cadastro.remover}">
   <h:outputText value="Excluir"></h:outputText>
</h:commandLink>

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 incluir() {		
		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.execute();
			cn.close();
			return "sucesso";
		} catch (SQLException e) {
			e.printStackTrace();
			return "falha";
			
		}		
	}

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

	
	/* (non-Javadoc)
	 * @see daca.service.PersistenteIF#selectTodos()
	 */
	public List getLista() {
		Connection cn = Conexao.obterConexao();
		List lista = new ArrayList();
		try {			
		
			ResultSet rs = cn.createStatement().executeQuery("select id,login,senha,mail 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);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}		
		return lista;
	}

}
<faces-config>

    <application>


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

      <message-bundle>daca.bundle.Messages</message-bundle>
    
    </application>
  
  
    <navigation-rule>
		
		<from-view-id>/login.jsp</from-view-id>
		
		<navigation-case>
			<from-outcome>sucesso</from-outcome>
			<to-view-id>/login.jsp</to-view-id>
		</navigation-case>
		
		<navigation-case>
			<from-outcome>falha</from-outcome>
			<to-view-id>/teste.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>


    <managed-bean>
        <managed-bean-name>cadastro</managed-bean-name>
        <managed-bean-class>daca.bean.Usuario</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    

Amigo voce poderia fazer algo do tipo…

<h:commandLink actionListener="#{bancosbean.excluir}" onclick="javascript:if (!confirm('Deseja excluir este registro?')) return false;"> <f:param id="idBanco" name="idBanco" value="#{bancos.id}"/> <h:graphicImage title="Exluir este registro (#{bancos.id})" value="../__designer/images/ico_lixeira.png" style="border: none;" /> </h:commandLink>

na classe:

[code]
public void excluir(ActionEvent event) {
String value = ((UIParameter) event.getComponent().findComponent(“idBanco”)).getValue().toString();
remover(Integer.parseInt(value));
}

private String remover(int id) {
try {
Connection cn = Conexao.obterConexao();
PreparedStatement statement = null;
System.out.println(“id=”+id);
statement = cn.prepareStatement(“delete from usuario where id=?”);
statement.setInt(1,id);
statement.execute();
cn.close();
return “sucesso”;
} catch (SQLException e) {
e.printStackTrace();
return “falha”;
}
}[/code]

espero q possa te ajudar em algo, pois eu fiz uma aplicaçãozinha dessa maneira e funcionou.

e agora tentei fazer :

<h:commandLink action="#{cadastro.remover}">   
    <h:outputText value="Excluir" escape="false" />   
    <f:param name="codigo" value="#{usuario.id}" />   
  </h:commandLink>  

mas dá o erro :

Caused by: javax.faces.el.MethodNotFoundException: remover: daca.bean.Usuario.remover()
	at com.sun.faces.el.MethodBindingImpl.method(MethodBindingImpl.java:206)
	at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:124)
	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
	... 22 more
22/02/2008 15:57:08 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
javax.faces.el.MethodNotFoundException: remover: daca.bean.Usuario.remover()
	at com.sun.faces.el.MethodBindingImpl.method(MethodBindingImpl.java:206)
	at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:124)
	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
	at javax.faces.component.UICommand.broadcast(UICommand.java:312)
	at javax.faces.component.UIData.broadcast(UIData.java:657)
	at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
	at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
	at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
	at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
	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)
public String remover(int codigo) {
		try {			
			Connection cn = Conexao.obterConexao();
	        PreparedStatement statement = null;
	        System.out.println("id="+codigo);
			statement = cn.prepareStatement("delete from usuario where id=?");
			statement.setInt(1,codigo);			
			statement.execute();
			cn.close();
			return "sucesso";
		} catch (SQLException e) {
			e.printStackTrace();
			return "falha";
		}		
	}

Amigo para vc usar seu metodo

 action="#{cadastro.remover}">     

dessa maneira, ele não pode receber parametro. pois o action não reconhece o metodo esperando parametro.

Caro Diego L. Rodrigues,

obrigado pelo retorno…estou fazendo igual ao exemplo que você me passou

mas o valor od codigo na hor ado metodo está chegando zero …

já passou por isso …se puder me ajudar agradeceria…

abs

NFO: Find registry server-registry.xml at classpath resource
22/02/2008 16:16:40 org.apache.catalina.startup.Catalina start
INFO: Server startup in 2047 ms
value=0
id=0


					
  <h:commandLink actionListener="#{cadastro.excluir}" >   
    <h:outputText value="Excluir"></h:outputText>
    <f:param id="id" name="id" value="#{cadastro.id}"/>   
</h:commandLink> 
public void excluir(ActionEvent event) {   
	    String value = ((UIParameter) event.getComponent().findComponent("id")).getValue().toString();
	    System.out.println("value="+value);
	    remover(Integer.parseInt(value));   
	}   

	public String remover(int codigo) {
		try {			
			Connection cn = Conexao.obterConexao();
	        PreparedStatement statement = null;
	        System.out.println("id="+codigo);
			statement = cn.prepareStatement("delete from usuario where id=?");
			statement.setInt(1,codigo);			
			statement.execute();
			cn.close();
			return "sucesso";
		} catch (SQLException e) {
			e.printStackTrace();
			return "falha";
		}		
	}