dev@javaserverfaces.java.net

Let's come back to #3241 now

From: zhijun Ren <ren.zhijun_at_oracle.com>
Date: Sun, 28 Sep 2014 15:44:52 +0800

Hi Ed and Manfred,

Now it's time back to handle JAVASERVERFACES-3241
<https://java.net/jira/browse/JAVASERVERFACES-3241> now, after several
round discussions and tests, I still think the following change is safe
and reasonable:

https://java.net/jira/secure/attachment/53683/changebundle.txt


Only need 1 line change:

Index: jsf-api/src/main/java/javax/faces/component/AttachedObjectListHolder.java
===================================================================
--- jsf-api/src/main/java/javax/faces/component/AttachedObjectListHolder.java (revision 13651)
+++ jsf-api/src/main/java/javax/faces/component/AttachedObjectListHolder.java (working copy)
@@ -157,7 +157,7 @@
              for (int i = 0, len = attachedObjects.length; i< len; i++) {
                  T restored = (T) ((StateHolderSaver) attachedObjects[i]).restore(context);
                  if (restored != null) {
- this.attachedObjects.add(restored);
+ add(restored);
                  }
              }
          } else {


The change is in restoreState() and the AttachedObjectListHolder's add()
method is as following:

/ void add(T attachedObject) {

         clearInitialState(); *<=== this will make difference with old code*
         attachedObjects.add(attachedObject);

     }/

The difference is that the initialState is set to false and it changes
the logic in the saveState() method:

/ if (initialState) {
             Object[] attachedObjects = new
Object[this.attachedObjects.size()];
             boolean stateWritten = false;
             for (int i = 0, len = attachedObjects.length; i < len; i++) {
                 T attachedObject = this.attachedObjects.get(i);
                 if (attachedObject instanceof StateHolder) {
                     StateHolder sh = (StateHolder) attachedObject;
                     if (!sh.isTransient()) {
                         attachedObjects[i] = sh.saveState(context);
                     }
                     if (attachedObjects[i] != null) {
                         stateWritten = true;
                     }
                 }
             }
             return ((stateWritten) ? attachedObjects : null);
         } else { *<====== this part will be called since the
initialState is false*

             Object[] attachedObjects = new
Object[this.attachedObjects.size()];
             for (int i = 0, len = attachedObjects.length; i < len; i++) {
                 attachedObjects[i] =
UIComponentBase.saveAttachedState(context, this.attachedObjects.get(i));
             }
             return (attachedObjects);
         }/

Please review and feedback, if you agree, I will commit code.


BR,
Zhijun