In my JSF page, i am trying to remove an element from a collection. Instead of calling the Collection.remove(Object o)
method, i think the page calls Vector.remove(int i)
.
Update: tagsCollection is type of org.eclipse.persistence.indirection.IndirectList
Update: It gives the same exception with Vector
With the code below i get the following error:
java.lang.IllegalArgumentException: Cannot convert com.question.entities.Tags[ tagId=12 ] of type class com.question.entities.Tags to int
<ui:repeat value="#{backingBean.question.tagsCollection}" var="tag" >
<li>
<span>#{tag.tagTitle}</span>
<h:commandButton>
<f:ajax event="click" listener="#{backingBean.question.tagsCollection.remove(tag)}" render="@form" execute="@form"/>
</h:commandButton>
</li>
</ui:repeat>
Update: Here is the minimum code that can generate the exception. It throws the following exception:
java.lang.IllegalArgumentException: Cannot convert true of type class java.lang.Boolean to int
index.xhtml
<?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:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form id="form">
<ui:repeat value="#{backingBean.myList}" var="tag">
#{tag.booleanValue()}
<h:commandButton value="Delete">
<f:ajax listener="#{backingBean.myList.remove(tag)}" execute="@form" render="@form"/>
</h:commandButton>
</ui:repeat>
</h:form>
</h:body>
</html>
BackingBean.java
@Named
@ViewScoped
public class BackingBean implements Serializable {
private Collection<Boolean> myList = new Vector<Boolean>();
public BackingBean() {
myList.add(true);
myList.add(false);
myList.add(true);
}
public Collection<Boolean> getMyList() {
return myList;
}
public void setMyList(Collection<Boolean> myList) {
this.myList = myList;
}
}