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

时间:2014-11-20 16:41:43

标签: jsf jsf-2 el

在我的JSF页面中,我试图从集合中删除一个元素。我认为页面调用Collection.remove(Object o)

,而不是调用Vector.remove(int i)方法

更新: tagsCollection的类型为org.eclipse.persistence.indirection.IndirectList

更新:它使用Vector

提供相同的异常

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

  

java.lang.IllegalArgumentException:无法转换   com.question.entities.Tags [tagId = 12]类型类   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:无法转换类型类的true   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;
    }

}

1 个答案:

答案 0 :(得分:0)

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