You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Cagatay Civici <ca...@gmail.com> on 2006/10/15 01:26:32 UTC

SaveState Issues

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

Re: SaveState Issues

Posted by Martin Marinschek <ma...@gmail.com>.
Sounds good!

regards,

Martin

On 10/15/06, Cagatay Civici <ca...@gmail.com> wrote:
> Yes Marting that's exactly the problem. After digging more, I've realized
> that we dont need to change anything in restoreState of the component
> because calling restoreAttachedState will simply return the value if it's
> not a special wrapped type.
>
> 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 =
> restoreAttachedState(context,values[1]);
>
>         ValueBinding vb = getValueBinding("value");
>         if (vb != null)
>         {
>             vb.setValue(context, value);
>         }
>     }
>
> This works good both with stateholders and lists, also the ugly part is
> removed since we dont need to tell the component to take special care during
> restoreState.
>
> Cagatay
>
>
> On 10/15/06, Martin Marinschek <ma...@gmail.com> wrote:
> > 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 < matzew@apache.org> 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 <ca...@gmail.com> 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
> >
>
>


-- 

http://www.irian.at

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

Professional Support for Apache MyFaces

Re: SaveState Issues

Posted by Cagatay Civici <ca...@gmail.com>.
Yes Marting that's exactly the problem. After digging more, I've realized
that we dont need to change anything in restoreState of the component
because calling restoreAttachedState will simply return the value if it's
not a special wrapped type.

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 = restoreAttachedState(context,values[1]);

        ValueBinding vb = getValueBinding("value");
        if (vb != null)
        {
            vb.setValue(context, value);
        }
    }

This works good both with stateholders and lists, also the ugly part is
removed since we dont need to tell the component to take special care during
restoreState.

Cagatay

On 10/15/06, Martin Marinschek <ma...@gmail.com> wrote:
>
> 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 <ma...@apache.org> 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 <ca...@gmail.com> 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
>

Re: SaveState Issues

Posted by Martin Marinschek <ma...@gmail.com>.
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 <ma...@apache.org> 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 <ca...@gmail.com> 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

Re: SaveState Issues

Posted by Matthias Wessendorf <ma...@apache.org>.
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 <ca...@gmail.com> 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