javax.el.ELException: /test.xhtml @14,60 value="#{valueHolder.value}": java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

Java.net JIRA | jasonzhang2002gmailcom | 3 years ago
  1. 0

    I tried to edit/delete a list of integer. Since primitive object can not be editted(http://blog.flexdms.com/2012/07/jsf-datatable-and-primitive-type.html), I used a wrapper class. {code} @ViewScoped @Named public class Test implements Serializable { /** * */ private static final long serialVersionUID = 1L; List<Integer> ints=new ArrayList<Integer>(); ValueHolderList vl=new ValueHolderList(); public Test() { ints.add(1); /* ints.add(2); ints.add(3); ints.add(4); ints.add(5); */ } public ValueHolderList getList() { return vl; } public void removeInt(int index) { ints.remove(index); } public class ValueHolder { int index; public ValueHolder(int index) { super(); this.index = index; } public int getValue() { return ints.get(index); } public void setValue(int value) { ints.set(index, value); } } public class ValueHolderList extends AbstractList<ValueHolder> { public ValueHolderList() { super(); } public ValueHolder get(int index) { return new ValueHolder(index); } @Override public int size() { return ints.size(); } } } {code} facelet page {code:xml} <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> <h:head> </h:head> <h:body> <h:form id="f"> <h:panelGroup id="top"> <table> <ui:repeat var="valueHolder" value="#{test.list}" varStatus="status" id="r"> <tr> <td><h:inputText value="#{valueHolder.value}" id="i"></h:inputText></td> <td><h:commandButton value="remove" id="b" actionListener="#{test.removeInt(status.index)}"> <f:ajax execute=":f:top" render=":f:top"></f:ajax> </h:commandButton></td> </tr> </ui:repeat> </table> </h:panelGroup> </h:form> </h:body> </html> {code} The click the remove button at web page. The server will report a java.lang.IndexOutOfBoundsException {code} javax.el.ELException: /test.xhtml @14,60 value="#{valueHolder.value}": java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) at javax.faces.component.UIOutput.getValue(UIOutput.java:174) at javax.faces.component.UIInput.getValue(UIInput.java:291) at com.sun.faces.facelets.component.UIRepeat$SavedState.populate(UIRepeat.java:829) at com.sun.faces.facelets.component.UIRepeat.saveChildState(UIRepeat.java:370) at com.sun.faces.facelets.component.UIRepeat.saveChildState(UIRepeat.java:356) at com.sun.faces.facelets.component.UIRepeat.setIndex(UIRepeat.java:441) at com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:553) at com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:990) {code} It seems that the UIRepeat tries to refers an object that is already invalid(deleted in this case) business-wise. I guess there should be no problem if I use a regular object which just returns cached value. The regular object, although invalid, is still in memory and its method can be invoked. However, if the regular performs some business validation before returning a value, we should have some sort of application-specific error. By the way, is there a need to save the model state(ValueHolder.value) here? The value should always be in model layer. It can be retrieved if needed.

    Java.net JIRA | 3 years ago | jasonzhang2002gmailcom
    javax.el.ELException: /test.xhtml @14,60 value="#{valueHolder.value}": java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
  2. 0

    I tried to edit/delete a list of integer. Since primitive object can not be editted(http://blog.flexdms.com/2012/07/jsf-datatable-and-primitive-type.html), I used a wrapper class. {code} @ViewScoped @Named public class Test implements Serializable { /** * */ private static final long serialVersionUID = 1L; List<Integer> ints=new ArrayList<Integer>(); ValueHolderList vl=new ValueHolderList(); public Test() { ints.add(1); /* ints.add(2); ints.add(3); ints.add(4); ints.add(5); */ } public ValueHolderList getList() { return vl; } public void removeInt(int index) { ints.remove(index); } public class ValueHolder { int index; public ValueHolder(int index) { super(); this.index = index; } public int getValue() { return ints.get(index); } public void setValue(int value) { ints.set(index, value); } } public class ValueHolderList extends AbstractList<ValueHolder> { public ValueHolderList() { super(); } public ValueHolder get(int index) { return new ValueHolder(index); } @Override public int size() { return ints.size(); } } } {code} facelet page {code:xml} <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> <h:head> </h:head> <h:body> <h:form id="f"> <h:panelGroup id="top"> <table> <ui:repeat var="valueHolder" value="#{test.list}" varStatus="status" id="r"> <tr> <td><h:inputText value="#{valueHolder.value}" id="i"></h:inputText></td> <td><h:commandButton value="remove" id="b" actionListener="#{test.removeInt(status.index)}"> <f:ajax execute=":f:top" render=":f:top"></f:ajax> </h:commandButton></td> </tr> </ui:repeat> </table> </h:panelGroup> </h:form> </h:body> </html> {code} The click the remove button at web page. The server will report a java.lang.IndexOutOfBoundsException {code} javax.el.ELException: /test.xhtml @14,60 value="#{valueHolder.value}": java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) at javax.faces.component.UIOutput.getValue(UIOutput.java:174) at javax.faces.component.UIInput.getValue(UIInput.java:291) at com.sun.faces.facelets.component.UIRepeat$SavedState.populate(UIRepeat.java:829) at com.sun.faces.facelets.component.UIRepeat.saveChildState(UIRepeat.java:370) at com.sun.faces.facelets.component.UIRepeat.saveChildState(UIRepeat.java:356) at com.sun.faces.facelets.component.UIRepeat.setIndex(UIRepeat.java:441) at com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:553) at com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:990) {code} It seems that the UIRepeat tries to refers an object that is already invalid(deleted in this case) business-wise. I guess there should be no problem if I use a regular object which just returns cached value. The regular object, although invalid, is still in memory and its method can be invoked. However, if the regular performs some business validation before returning a value, we should have some sort of application-specific error. By the way, is there a need to save the model state(ValueHolder.value) here? The value should always be in model layer. It can be retrieved if needed.

    Java.net JIRA | 3 years ago | jasonzhang2002gmailcom
    javax.el.ELException: /test.xhtml @14,60 value="#{valueHolder.value}": java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
  3. 0

    Avoid default int value of 0 to display in h:inputText

    Stack Overflow | 3 years ago | yahh
    javax.el.ELException: /index.xhtml @23,66 value="#{userIdea.idea.empid}": java.lang.NullPointerException
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Error hibernate when i have two class. "org.hibernate.exception.SQLGrammarException: could not prepare statement

    Stack Overflow | 2 years ago | ProSyth
    javax.el.ELException: /pages/index.xhtml @15,73 value="#{empresaBean.getEmpresaList()}": org.hibernate.exception.SQLGrammarException: could not prepare statement
  6. 0

    HTTP status 500. java.lang.NullPointerException when I link other page with datatable

    Stack Overflow | 2 years ago | ProSyth
    javax.el.ELException: /pages/menu/menuPrincipal.xhtml @17,70 value="#{ldiarioBean.getLDiarioList()}": java.lang.NullPointerException

  1. marcbouvierdav 3 times, last 4 months ago
1 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. javax.el.ELException

    /test.xhtml @14,60 value="#{valueHolder.value}": java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

    at com.sun.faces.facelets.el.TagValueExpression.getValue()
  2. JSF
    TagValueExpression.getValue
    1. com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
    1 frame
  3. JavaEE 7
    UIInput.getValue
    1. javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    2. javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
    3. javax.faces.component.UIOutput.getValue(UIOutput.java:174)
    4. javax.faces.component.UIInput.getValue(UIInput.java:291)
    4 frames
  4. JSF
    UIRepeat.encodeChildren
    1. com.sun.faces.facelets.component.UIRepeat$SavedState.populate(UIRepeat.java:829)
    2. com.sun.faces.facelets.component.UIRepeat.saveChildState(UIRepeat.java:370)
    3. com.sun.faces.facelets.component.UIRepeat.saveChildState(UIRepeat.java:356)
    4. com.sun.faces.facelets.component.UIRepeat.setIndex(UIRepeat.java:441)
    5. com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:553)
    6. com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:990)
    6 frames