title: Delete a specific row TO DATATABLE using jsf and mysql
body: <p>I'm trying for four days to pass a value from my (xadmin.xhtml) to my (JadminBeans.java) but no luck so far. what i want to do is when i push the delete button inside a row using datatable all the data inside that row should be deleted form my datatable and mysql database. so this is a part of my code :
  P.s: i'm new to java EE and jsf</p>
  
  <p><strong>xadmin.xhtml</strong></p>
  
  <pre><code>&lt;h:dataTable value="#{Jadmin.messages}" var="o"
              styleClass="order-table"
              headerClass="order-table-header"
              rowClasses="order-table-odd-row,order-table-even-row"
          &gt;
  
          &lt;h:column&gt;
  
              &lt;f:facet name="header"&gt;username&lt;/f:facet&gt;
              #{o.username}
  
          &lt;/h:column&gt;
  
          &lt;h:column&gt;
  
              &lt;f:facet name="header"&gt;password&lt;/f:facet&gt;
              #{o.password}
  
          &lt;/h:column&gt;
  
          &lt;h:column&gt;
  
              &lt;f:facet name="header"&gt;permission&lt;/f:facet&gt;
              #{o.permission}
  
          &lt;/h:column&gt;
  
  
          &lt;h:column&gt;
  
              &lt;f:facet name="header"&gt;delete&lt;/f:facet&gt;
  
              &lt;h:commandLink value="Delete" action="#{Jadmin.delete(o.username)}" /&gt;
  
          &lt;/h:column&gt;
  
          &lt;/h:dataTable&gt;
  </code></pre>
  
  <p><strong>JadminBeans.java</strong></p>
  
  <pre><code>@ManagedBean(name = "Jadmin")
  @SessionScoped
  public class JadminBeans {
  
      private String username, password, permission;
      private JadminController JaC;
  
      // insert getter setter here
      public List&lt;JadminBeans&gt; getMessages() {
          return JadminDAO.getAllUsers();
      }
      public String getUsername() {
          return username;
      }
      public void setUsername(String username) {
          this.username = username;
      }
      public String getPassword() {
          return password;
      }
      public void setPassword(String password) {
          this.password = password;
      }
      public String getPermission() {
          return permission;
      }
      public void setPermission(String permission) {
          this.permission = permission;
      }
  
  
    public void  delete(String usr) {
  
       System.out.println("JadminBeans &gt;&gt; delete() ---------- username= "+usr);
        JadminDAO.deleteUser(usr);
  
      }
  
  } 
  </code></pre>
  
  <p><strong>JadminDAO.java</strong></p>
  
  <pre><code> public static List&lt;JadminBeans&gt; getAllUsers() {
          List&lt;JadminBeans&gt; users = new ArrayList&lt;JadminBeans&gt;();
          try {
              Connection con = DBconnection.getConnection();
              Statement statement = connection.createStatement();
              ResultSet rs = statement.executeQuery("select * from users");
              while (rs.next()) {
                  JadminBeans user = new JadminBeans();
                   user.setUsername(rs.getString("username"));
                   user.setPassword(rs.getString("password"));
                   user.setPermission(rs.getString("permission"));
  
                   System.out.println("JadminDAO &gt; getAllUsers(): "+rs.getString("username"));
  
                  users.add(user);
              }
          } catch (SQLException e) {
              e.printStackTrace();
          }
  
          return users;
      }
  public static void deleteUser(String id) {
          try {
              PreparedStatement preparedStatement = connection.prepareStatement("delete from users where username=?");
              // Parameters start with 1
              preparedStatement.setString(1, id);
              preparedStatement.executeUpdate();
              System.out.println("JadminDAO &gt;&gt; deleteUser ----------"+ id);
  
          } catch (SQLException e) {
              System.out.println("JadminDAO &gt;&gt; deleteUser----------- SQLException :(");
              e.printStackTrace();
          }
      }
  </code></pre>