gpt4 book ai didi

jsf - EL 调用 remove(int i) 而不是 remove(Object o)

转载 作者:行者123 更新时间:2023-12-04 19:30:07 28 4
gpt4 key购买 nike

<分区>

在我的 JSF 页面中,我试图从集合中删除一个元素。我认为页面调用的不是 Collection.remove(Object o) 方法,而是调用 Vector.remove(int i)

更新: tagsCollection 是 org.eclipse.persistence.indirection.IndirectList

的类型

更新:它给出与 Vector 相同的异常

使用下面的代码我得到以下错误:

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;
}

}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com