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

标签 jsf jsf-2 el

<分区>

在我的 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;
    }

}

最佳答案

老实说,我不知道 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);
}

关于jsf - EL 调用 remove(int i) 而不是 remove(Object o),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27044936/

相关文章:

css - 防止eclipse破坏CSS格式

jsf - 带转换器的复合 JSF 组件

jsf-2 - 如何将 Primefaces inputMask 限制为仅数字?

spring - Primefaces fileUpload 不起作用,FileUploadFilter 调用两次

java - Maven Central 中提供哪些 EL 2.2 实现?

jsf - 避免JSF中el中的空点异常

java - FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance()) 返回 null

javascript - 使用 jQuery 将 html 代码插入 Primefaces 对话框

java - 从 JSF 中的子类访问属性时出错

java - Eclipse (Kepler) 中的 Faces 配置架构验证问题