I’m working with a DataTable component, and my very straightforward goal is to delete a row using an inline command button. This is the code for the dataTable component.
<p:dataTable rowKey="#{dobavljac.dobavljacID}" value="#{dobavljacMB.vratiDobavljace()}" var="dobavljac" >
<p:column>
<f:facet name="header">ID</f:facet>
<h:outputText value="#{dobavljac.dobavljacID}" />
</p:column>
<p:column>
<f:facet name="header">Naziv</f:facet>
<h:outputText value="#{dobavljac.naziv}" />
</p:column>
<p:column>
<f:facet name="header">Adresa</f:facet>
<h:outputText value="#{dobavljac.adresa}" />
</p:column>
<p:column colspan="2" style="text-align: center">
<f:facet name="header">Operacija</f:facet>
<p:commandButton id="viewButton" style="height: 35px" value="Delete" action="#{dobavljacMB.obrisi(dobavljac)}" ajax="false"/>
</p:column>
</p:dataTable>
“dobavljac” is the entity I need to delete using action=”#{dobavljacMB.obrisi(dobavljac)}”
The managed bean class that has the deleting function “obrisi” is as follows:
/**
* Creates a new instance of DobavljacMB
*/
private Dobavljac tekuci;
public Dobavljac getTekuci() {
return tekuci;
}
public void setTekuci(Dobavljac tekuci) {
this.tekuci = tekuci;
}
public DobavljacMB() {
}
public String prikazDobavljaca() {
System.out.println("Prikaz dobavljaca");
// System.out.println("podaci su:"+tekuciKorisnik.getKorisnickoIme());
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Ne postoji korisnik sa tim korisnickim imenom i sifrom!", ""));
return null;
}
public List<Dobavljac> vratiDobavljace() {
return KonekcijaDB.vratiInstancu().vratiDobavljace();
}
public String obrisi(Dobavljac d){
try {
System.out.println("obrisi");
KonekcijaDB.vratiInstancu().obrisi(d);
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Dobavljac obrisan", ""));
return "prikazDobavljaca.xhtml";
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Greska pri brisanju", ""));
return "prikazDobavljaca.xhtml";
}
}
The Dobavljac class is a simple POJO class, generated by the IDE, so no need to post it. The problem is that when the method is called, it throws a
java.lang.IllegalArgumentException: Cannot convert model.Dobavljac[ dobavljacID=66 ] of type class model.Dobavljac to class model.Dobavljac which is pretty absurd, since the object passed is the same as the one in the MB method “obrisi(Dobavljac d)”.
Of course, the object is never deleted from the DB, since the method is not invoked. My thoughts are that it’s a PrimeFaces problem, and not one of the JSF.
I’ve found examples that are very similar to this, and found that no one had this kind of problem (conversion between same classes), and don’t need to implement a converter.
I’m not sure if I need to add some more info to the question, and I’d be most thankful for an answer. It is very annoying. Thanks!
The webapp’s runtime classpath is dirty. There are multiple class file definitions of the
model.Dobavljacclass, each loaded by a differentClassLoader. The webapp’s runtime classpath covers by default all class files in/WEB-INF/classes, all JAR files/WEB-INF/lib, all JAR files in server’s/lib, all JAR files in JRE’s/liband/lib/ext. The server can have other folders added via specific configuration settings. How and which exactly depends on the server’s make/version which you didn’t tell anything about.Cleanup the runtime classpath and get rid of the duplicate class file definiton (either the just standalone
.classfile, or the JAR file containing the offending.classfile). After a rebuild/redeploy/restart this problem should disappear.