在JSF页面中,我试图从集合中删除一个元素。我认为页面不是调用Collection.remove(Object o)方法,而是调用Vector.remove(int i)。
更新: tagsCollection是org.eclipse.persistence.indirection.IndirectList类型
更新:它给出了与向量相同的异常
通过下面的代码,我得到了以下错误:
java.lang.IllegalArgumentException:无法将类型为com.question.entities.Tags的com.question.entities.Tags tagId=12转换为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> 更新:这里的是可以生成异常的最小代码。它引发以下异常:
java.lang.IllegalArgumentException:无法将java.lang.Boolean类型的true转换为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;
}
}发布于 2014-11-20 16:50:12
老实说,我不知道JSF在后台是如何处理这个问题的,但是为了避免这种情况,只需调用您自己的bean方法就可以了
<f:ajax event="click" listener="#{backingBean.removeTag(backingBean.question, tag)}" render="@form" execute="@form"/>
public void removeTag(Question question, Tag tag) {
question.getTagsCollection().remove(tag);
}https://stackoverflow.com/questions/27044936
复制相似问题