I have a datatable to display some informations about users and the last column contains a command button to delete the row. the problem is when i click on any button all rows are deleted that is the action is invoked many times. My Xhtml file:
<h:form>
<p:dataTable var="user" value="#{admin.users}">
<p:column headerText="Login">
<h:outputText value="#{user.login}" />
</p:column>
<p:column headerText="Nom">
<h:outputText value="#{user.nom}" />
</p:column>
<p:column headerText="Prenom">
<h:outputText value="#{user.prenom}" />
</p:column>
<p:column headerText="Password">
<h:outputText value="#{user.password}" />
</p:column>
<p:column headerText="Operation">
<p:commandButton value="supprimer" onClick="#{admin.delete_user(user.login)}" ajax="false" />
</p:column>
</p:dataTable>
</h:form>
My bean
@ManagedBean (name="admin")
@ViewScoped
public class Admin {
private ArrayList<User> users;
//getters & setters
public String delete_user(String login)
{
System.out.println(login);
UserDao ud=new UserDao();
try{
ud.Delete_Query(login);
}
catch(Exception e ){System.out.println(e.getStackTrace());}
return"#";
}
}
when i click the commandbutton in any row , all users login are printed in the console.
You use an EL to call a method in a backingbean in an onclick
where you should put it in an action
instead. Onclick is just for javascript.
But this stil does not explain the behaviour you describe (but it could be that they log lines are already printed and you just 'think' they are printed when you click the button.) I'd expect all the delete actions to have taken place when the page is rendered.