EL calls remove (int i) instead of removing (Object o)

In my JSF page, I am trying to remove an item from a collection. Instead of calling a method Collection.remove(Object o)

, I think the page is calling Vector.remove(int i)

.

Update: tagsCollection is a typeorg.eclipse.persistence.indirection.IndirectList

Update: . This gives the same exception with Vector

With the code below, I am getting the following error:

java.lang.IllegalArgumentException: Unable to convert com.question.entities.Tags [tagId = 12] of type 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> 

      

Update: Here is the minimal code that can throw an exception. This throws the following exception:

java.lang.IllegalArgumentException: Cannot convert true from class type 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;
    }

}

      

+3


source to share


1 answer


To be honest, I don't know how JSF handles this in the background, but to avoid this, just call your own bean method that does the same



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

      

0


source







All Articles