L'attribut action de <h:commandButton>

Fermé
stevensen Messages postés 1 Date d'inscription mercredi 28 décembre 2011 Statut Membre Dernière intervention 28 décembre 2011 - 28 déc. 2011 à 23:50
Bonjour,

je travaille sur un projet en JSF sous Netbeans et mon problème est le suivant :

- j'ai développé une vue jsf : index.xhtml voici son code :

<?xml version="1.0" encoding="UTF-8"?>
<!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:f="https://www.oracle.com/java/technologies/"
xmlns:h="https://www.oracle.com/java/technologies/">

<h:head>
<title>Suppression du contenu de la Table MySQL</title>
</h:head>
<h:body>
<h:form>
<h:commandButton value="Vider la table" action="Delete"></h:commandButton>
</h:form>
</h:body>
</html>

- et voici la classe Delete.java appelée par l'attribut action de <h:commandButton> :

import java.sql.*;

public class Delete{
public static void main(String[] args) {
System.out.println
("Example for Deleting All Rows from a database Table!");
Connection con = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection
("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");
try{
Statement st = con.createStatement();
String sql = "DELETE FROM employee";
int delete = st.executeUpdate(sql);
if(delete == 0){
System.out.println("All rows are completelly deleted!");
}
}
catch(SQLException s){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
}
}

Mon problème est quand je clique sur le bouton : "Vider la table" dans la page index.xhtml rien ne se passe ! (la classe Delete.java) n'est pas appelée (exécutée)).

je demande si vous avez une solution pour mon problème ou toute autre solution qui permettra d'exécuter cette classe Java à partir du bouton de la vue jsf.


Merci d'avance