Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.1
    • Fix Version/s: 2.1.26, 2.2.3
    • Component/s: state saving
    • Labels:
      None
    • Environment:

      glassfish 4.0 mojarra 2.2.1

      Description

      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.

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

      facelet page

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

      The click the remove button at web page. The server will report a java.lang.IndexOutOfBoundsException

      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)
      

      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.

        Issue Links

          Activity

          Hide
          jasonzhang2002gmailcom added a comment -

          I have another exception which may be caused by the same problem. The input is under UI:repeat. The state is saved as className. At restoreView time, the statehelper tries to instantiate the instance by new method. The class is an non-static inner class. The instantiation will fail.

          At the first encode time, the call stack is like this

          ui:repeat line 453: restoreChildState
          ui:repeat line 483: setIndex(-1)
          ui:repeat line 990:process
          

          Again, why is the value should be saved? Input text usually does not save its value since its value can be looked up by binding all the time. The Value Expression(Object or literal String) should be saved instead of the evaluated object even the value should be saved. Right?

          -jason

          Show
          jasonzhang2002gmailcom added a comment - I have another exception which may be caused by the same problem. The input is under UI:repeat. The state is saved as className. At restoreView time, the statehelper tries to instantiate the instance by new method. The class is an non-static inner class. The instantiation will fail. At the first encode time, the call stack is like this ui:repeat line 453: restoreChildState ui:repeat line 483: setIndex(-1) ui:repeat line 990:process Again, why is the value should be saved? Input text usually does not save its value since its value can be looked up by binding all the time. The Value Expression(Object or literal String) should be saved instead of the evaluated object even the value should be saved. Right? -jason
          Hide
          Manfred Riem added a comment -

          Applied to 2.1 branch,

          svn commit -m "Fixes https://java.net/jira/browse/JAVASERVERFACES-2938, r=rogerk, make sure UIRepeat does not try to save state for index -1"
          Sending jsf-ri\src\main\java\com\sun\faces\facelets\component\UIRepeat.java
          Adding test\agnostic\facelets\ui\src\main\java\com\sun\faces\test\agnostic\facelets\ui\RepeatRemovedBean.java
          Adding test\agnostic\facelets\ui\src\main\webapp\index.xhtml
          Adding test\agnostic\facelets\ui\src\main\webapp\repeatRemoved.xhtml
          Adding test\agnostic\facelets\ui\src\test\java\com\sun\faces\test\agnostic\facelets\ui\Issue2938IT.java
          Transmitting file data .....
          Committed revision 12271.

          Show
          Manfred Riem added a comment - Applied to 2.1 branch, svn commit -m "Fixes https://java.net/jira/browse/JAVASERVERFACES-2938 , r=rogerk, make sure UIRepeat does not try to save state for index -1" Sending jsf-ri\src\main\java\com\sun\faces\facelets\component\UIRepeat.java Adding test\agnostic\facelets\ui\src\main\java\com\sun\faces\test\agnostic\facelets\ui\RepeatRemovedBean.java Adding test\agnostic\facelets\ui\src\main\webapp\index.xhtml Adding test\agnostic\facelets\ui\src\main\webapp\repeatRemoved.xhtml Adding test\agnostic\facelets\ui\src\test\java\com\sun\faces\test\agnostic\facelets\ui\Issue2938IT.java Transmitting file data ..... Committed revision 12271.
          Hide
          Manfred Riem added a comment -

          Applied to 2.2 branch,

          svn commit -m "Fixes https://java.net/jira/browse/JAVASERVERFACES-2938, r=rogerk, make sure UIRepeat does not try to save state for index -1"
          Sending jsf-ri\src\main\java\com\sun\faces\facelets\component\UIRepeat.java
          Adding test\agnostic\facelets\ui\src\main\java\com\sun\faces\test\agnostic\facelets\ui\RepeatRemovedBean.java
          Adding test\agnostic\facelets\ui\src\main\webapp\index.xhtml
          Adding test\agnostic\facelets\ui\src\main\webapp\repeatRemoved.xhtml
          Adding test\agnostic\facelets\ui\src\test\java\com\sun\faces\test\agnostic\facelets\ui\Issue2938IT.java
          Transmitting file data .....
          Committed revision 12272.

          Show
          Manfred Riem added a comment - Applied to 2.2 branch, svn commit -m "Fixes https://java.net/jira/browse/JAVASERVERFACES-2938 , r=rogerk, make sure UIRepeat does not try to save state for index -1" Sending jsf-ri\src\main\java\com\sun\faces\facelets\component\UIRepeat.java Adding test\agnostic\facelets\ui\src\main\java\com\sun\faces\test\agnostic\facelets\ui\RepeatRemovedBean.java Adding test\agnostic\facelets\ui\src\main\webapp\index.xhtml Adding test\agnostic\facelets\ui\src\main\webapp\repeatRemoved.xhtml Adding test\agnostic\facelets\ui\src\test\java\com\sun\faces\test\agnostic\facelets\ui\Issue2938IT.java Transmitting file data ..... Committed revision 12272.
          Hide
          Manfred Riem added a comment -

          Applied on 2.1 branch,

          svn commit -m "Reverting UIRepeat changes as they are failing on FSS."
          Sending jsf-ri\src\main\java\com\sun\faces\facelets\component\UIRepeat.java
          Sending test\agnostic\facelets\ui\src\test\java\com\sun\faces\test\agnostic\facelets\ui\Issue2938IT.java
          Transmitting file data ..
          Committed revision 12282.

          Show
          Manfred Riem added a comment - Applied on 2.1 branch, svn commit -m "Reverting UIRepeat changes as they are failing on FSS." Sending jsf-ri\src\main\java\com\sun\faces\facelets\component\UIRepeat.java Sending test\agnostic\facelets\ui\src\test\java\com\sun\faces\test\agnostic\facelets\ui\Issue2938IT.java Transmitting file data .. Committed revision 12282.
          Hide
          Manfred Riem added a comment -

          Applied to 2.2 branch,

          svn commit -m "Reverting UIRepeat changes as they are failing on FSS."
          Sending jsf-ri\src\main\java\com\sun\faces\facelets\component\UIRepeat.java
          Sending test\agnostic\facelets\ui\src\test\java\com\sun\faces\test\agnostic\facelets\ui\Issue2938IT.java
          Transmitting file data ..
          Committed revision 12283.

          Show
          Manfred Riem added a comment - Applied to 2.2 branch, svn commit -m "Reverting UIRepeat changes as they are failing on FSS." Sending jsf-ri\src\main\java\com\sun\faces\facelets\component\UIRepeat.java Sending test\agnostic\facelets\ui\src\test\java\com\sun\faces\test\agnostic\facelets\ui\Issue2938IT.java Transmitting file data .. Committed revision 12283.
          Hide
          Manfred Riem added a comment -

          Applied to 2.2 branch,

          svn commit -m "Fixes https://java.net/jira/browse/JAVASERVERFACES-2938, r=rogerk, make sure that 1) child state is not saved if the row is not available, 2) after rendering the child components clientIds are reset."
          Sending jsf-ri\src\main\java\com\sun\faces\facelets\component\UIRepeat.java
          Sending test\agnostic\facelets\ui\src\test\java\com\sun\faces\test\agnostic\facelets\ui\Issue2938IT.java
          Transmitting file data ..
          Committed revision 12417.

          Show
          Manfred Riem added a comment - Applied to 2.2 branch, svn commit -m "Fixes https://java.net/jira/browse/JAVASERVERFACES-2938 , r=rogerk, make sure that 1) child state is not saved if the row is not available, 2) after rendering the child components clientIds are reset." Sending jsf-ri\src\main\java\com\sun\faces\facelets\component\UIRepeat.java Sending test\agnostic\facelets\ui\src\test\java\com\sun\faces\test\agnostic\facelets\ui\Issue2938IT.java Transmitting file data .. Committed revision 12417.
          Hide
          jasonzhang2002gmailcom added a comment -

          Still see the same error in 2.2.2.

          Show
          jasonzhang2002gmailcom added a comment - Still see the same error in 2.2.2.
          Hide
          Manfred Riem added a comment -

          That is correct. As noted this is fixed in 2.2.3.

          Show
          Manfred Riem added a comment - That is correct. As noted this is fixed in 2.2.3.
          Hide
          jasonzhang2002gmailcom added a comment -

          Confirmed. This is solved in 2.2.3

          Show
          jasonzhang2002gmailcom added a comment - Confirmed. This is solved in 2.2.3

            People

            • Assignee:
              Manfred Riem
              Reporter:
              jasonzhang2002gmailcom
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: