在我的JSF页面中,我试图从集合中移除一个元素。而不是调用Collection.remove(Object o)
方法,我认为页面调用Vector.remove(int i)
。EL调用remove(int i)而不是remove(Object o)
更新: tagsCollection是org.eclipse.persistence.indirection.IndirectList
更新的类型:它给出了矢量
同一异常有了下面的代码我得到以下错误:
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>
更新:这是可以生成异常的最小代码。它抛出以下异常:
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;
}
}
“tag”是什么类型? – kolossus 2014-11-20 21:06:11
这是一个“标签”对象。 – 2014-11-20 21:16:00
当您在'tagsCollection'后输入点时,您可以使用哪些删除方法? – 2014-11-20 23:43:02