Hello Manfred,

Here is a specific example where savestate would fail :
<x:saveState value="#{myLinkedList}/>

The save state would return a List, and not a LinkedList.
So if you use somewhere in your code myLinkedList.pool(), it would fail.
In fact it fails earlier, as the saved value can't be coerced to a LinkedList.

I think this is important as you expect the saveState to return exactly what you saved, and not a object with a different type.

In my applications, I have a base backing bean that uses this scheme :
public class BaseFace implements Serializable {

public LinkedList<Object> getStates(){
return new LinkedList<Object>();
}

/**
* Restore the states.
*/
public void setStates(@SuppressWarnings("unused") LinkedList<Object> states) throws Exception{
// NoOp
}
        ...
}

It's quite nice because at you can extend this class easily and still have an easy job saving / restoring the state :
public class BaseFaceForObjectWithUnid<T extends ObjectWithUnid> extends BaseFace {
        ...

@Override
public LinkedList<Object> getStates(){
LinkedList<Object> states = super.getStates();
states.add( object == null ? null : object.getUnid() );
return states;
}

@Override
public void setStates(LinkedList<Object> states) throws Exception{
super.setStates(states);
setUnid(states == null ? null : (String)states.poll());
}
        ...
}

It worked fine until the related UIComponentBase had been modified.
So I limited the case for ArrayList.

But I still have problems with this UIComponentBase.saveAttachedState code, as I guess similar problems with other types (like a custom class implementing List) could arrise.
What I understand is that we need this "trick" to check if the List doesn't contain any StateHolder.
If I'm right and if we still need that, then maybe we can do a recursive check for any StateHolder object, and if there is none, then just serialize the object.

By the way, it's not exactly clear for me why we need to have a special treatment for StateHolders.
Could you clarify this for me please ?

Thanks,

Sylvain.


On Wed, 2005-07-27 at 21:48 +0200, Manfred Geiler wrote:
Sylvain,
This change does not make much sense IMHO.
Why do you check for ArrayList instead of List. There is only a List
cast after that, so why not just check for List?
Is there anything a LinkedList does not correctly implement from the
List interface?!

-Manfred

2005/7/26, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
> Author: svieujot
> Date: Tue Jul 26 08:25:26 2005
> New Revision: 225327
> 
> URL: http://svn.apache.org/viewcvs?rev=225327&view=rev
> Log:
> Bugfix for savestate with a linkedlist (couldn't coerce a value of type "java.util.ArrayList" to type "java.util.LinkedList".
> 
> Modified:
>     myfaces/api/trunk/src/java/javax/faces/component/UIComponentBase.java
> 
> Modified: myfaces/api/trunk/src/java/javax/faces/component/UIComponentBase.java
> URL: http://svn.apache.org/viewcvs/myfaces/api/trunk/src/java/javax/faces/component/UIComponentBase.java?rev=225327&r1=225326&r2=225327&view=diff
> ==============================================================================
> --- myfaces/api/trunk/src/java/javax/faces/component/UIComponentBase.java (original)
> +++ myfaces/api/trunk/src/java/javax/faces/component/UIComponentBase.java Tue Jul 26 08:25:26 2005
> @@ -593,9 +593,9 @@
>                                             Object attachedObject)
>      {
>          if (attachedObject == null) return null;
> -        if (attachedObject instanceof List)
> +        if (attachedObject instanceof ArrayList)
>          {
> -            ArrayList lst = new ArrayList(((List)attachedObject).size());
> +            List lst = new ArrayList(((List)attachedObject).size());
>              for (Iterator it = ((List)attachedObject).iterator(); it.hasNext(); )
>              {
>                  lst.add(saveAttachedState(context, it.next()));
> 
> 
>

Reply via email to