The problem is that a list is internally not just serialized, but
specially treated (wrapped, and then on restore you have a different
list than you had before - no good).

And that's something that Cagatay understandably doesn't want

Cagatay, how about adding an additional parameter to the component (on
calling save-state) which tells the component on restore-state if it
should restore the value normally or via restoreAttachedState?

public Object saveState(FacesContext context)
   {
       Object values[] = new Object[3];
       values[0] = super.saveState(context);
       boolean stateHolder = getValue() instanceof StateHolder;
       values[1] =  stateHolder ? saveAttachedState(context,
getValue()) : getValue();
       values[2] =  Boolean.valueOf(stateHolder);
       return values;
   }

regards,

Martin

On 10/15/06, Matthias Wessendorf <[EMAIL PROTECTED]> wrote:
Hi catagay,

javax.faces.component._AttachedStateWrapper is pretty much myfaces_api isn't it?
so shouldn't be used inside the savastate custom comp.

can you explain why it is failing?

Thanks!


On 10/14/06, Cagatay Civici <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'd like to discuss the latest issues about the savestate component.
>
> In order to use the component with a value of type StateHolder,
> restoreAttachedState-saveAttachedState is used. But using
> them fails with list implementations other than arraylists.
>
> See this one;
>
> See this one;
> http://issues.apache.org/jira/browse/TOMAHAWK-738
>
> It seems restoreAttachedState-saveAttachedState should only
> be used when the value is a stateholder, I've found an ugly solution to the
> problem as;
>
> public Object saveState(FacesContext context)
>     {
>         Object values[] = new Object[2];
>         values[0] = super.saveState(context);
>         values[1] = getValue() instanceof StateHolder ?
> saveAttachedState(context, getValue()) : getValue();
>         return values;
>     }
>
>     public void restoreState(FacesContext context, Object state)
>     {
>         Object values[] = (Object[])state;
>         super.restoreState(context, values[0]);
>         Object value =
> values[1].getClass().getName().equals("
> javax.faces.component._AttachedStateWrapper") ?
> restoreAttachedState(context,values[1]) : values[1];
>
>         ValueBinding vb = getValueBinding("value");
>         if (vb != null)
>         {
>             vb.setValue(context, value);
>         }
>     }
>
> Since _AttachedStateWrapper is private, I cant use instanceof, using class
> name is the ugly part. Other than that it works fine with all cases.
>
> Any ideas about this?
>
> Cagatay
>
>
>
>
>


--
Matthias Wessendorf
http://tinyurl.com/fmywh

further stuff:
blog: http://jroller.com/page/mwessendorf
mail: mwessendorf-at-gmail-dot-com



--

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Reply via email to