You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Ken McArthur <ke...@adsea.com> on 2007/08/23 16:33:26 UTC

javax.faces.ViewState contents?

With client state saving, I was under the impression that only managed beans
in session scope or used in t:saveState would be serialized into the hidden
javax.faces.ViewState variable.  However, my application's creating
ViewStates in pages with very simple forms that are almost 70 kb long!

I'm thinking that if I serialized all managed beans in all scopes + resource
bundle, it might come to about that.

Do you know what specifically is stored in ViewState?  Put in other words,
what is best way to architect application to minimize size of ViewState
while still using client state saving?

Thanks, I appreciate any advice,
Ken

Re: javax.faces.ViewState contents?

Posted by simon <si...@chello.at>.
On Thu, 2007-08-23 at 15:00 -0400, Mike Kienenberger wrote:
> On 8/23/07, simon <sk...@apache.org> wrote:
> > I can't initially think of an easy way to narrow the problem down
> > either...
> 
> What about simply deleting parts of the view until the size of the
> saved state changes dramatically?   That should tell you which
> component(s) are contributing the most to the issue.

Good point!

Just a reminder, when using JSP, xml comments "<!--" are not enough to
remove JSF components, you need to use JSP "<%--" comments (or delete
the text). I only say this because I've made that mistake too many
times..

Cheers,

Simon



Re: javax.faces.ViewState contents?

Posted by Mike Kienenberger <mk...@gmail.com>.
On 8/23/07, simon <sk...@apache.org> wrote:
> I can't initially think of an easy way to narrow the problem down
> either...

What about simply deleting parts of the view until the size of the
saved state changes dramatically?   That should tell you which
component(s) are contributing the most to the issue.



On 8/23/07, simon <sk...@apache.org> wrote:
> On Thu, 2007-08-23 at 08:33 -0600, Ken McArthur wrote:
> >
> > With client state saving, I was under the impression that only managed
> > beans in session scope or used in t:saveState would be serialized into
> > the hidden javax.faces.ViewState variable.  However, my application's
> > creating ViewStates in pages with very simple forms that are almost 70
> > kb long!
> >
> > I'm thinking that if I serialized all managed beans in all scopes +
> > resource bundle, it might come to about that.
> >
> > Do you know what specifically is stored in ViewState?  Put in other
> > words, what is best way to architect application to minimize size of
> > ViewState while still using client state saving?
>
> Hmm..puzzling. All that is stored in the viewstate is the internal
> properties of the JSF components attached to the current UIViewRoot.
> Nothing from the http session gets included, unless you use t:saveState
> to explicitly attach an object to the JSF component tree.
>
> JSF components do all support an arbitrary map of attributes that user
> data can be stored in. I think this will cause it to also be saved.
> Perhaps you have some code that stores an object into the attribute map
> of a JSF component?
>
> I think a JSF text edit component would have the current contents of the
> textbox as state, which might be reasonably large. But then so would the
> html page as it also has the state.
>
> Large html tables might be a bit bulky. The actual objects that the row
> data is taken from are not stored, but there is a bit of state info
> about each row that gets kept.
>
> Other that that, nothing occurs to me.
>
> I can't initially think of an easy way to narrow the problem down
> either...
>
> Regards,
>
> Simon
>
>

Re: javax.faces.ViewState contents?

Posted by simon <sk...@apache.org>.
On Thu, 2007-08-23 at 08:33 -0600, Ken McArthur wrote:
> 
> With client state saving, I was under the impression that only managed
> beans in session scope or used in t:saveState would be serialized into
> the hidden javax.faces.ViewState variable.  However, my application's
> creating ViewStates in pages with very simple forms that are almost 70
> kb long! 
> 
> I'm thinking that if I serialized all managed beans in all scopes +
> resource bundle, it might come to about that.
> 
> Do you know what specifically is stored in ViewState?  Put in other
> words, what is best way to architect application to minimize size of
> ViewState while still using client state saving? 

Hmm..puzzling. All that is stored in the viewstate is the internal
properties of the JSF components attached to the current UIViewRoot.
Nothing from the http session gets included, unless you use t:saveState
to explicitly attach an object to the JSF component tree.

JSF components do all support an arbitrary map of attributes that user
data can be stored in. I think this will cause it to also be saved.
Perhaps you have some code that stores an object into the attribute map
of a JSF component?

I think a JSF text edit component would have the current contents of the
textbox as state, which might be reasonably large. But then so would the
html page as it also has the state.

Large html tables might be a bit bulky. The actual objects that the row
data is taken from are not stored, but there is a bit of state info
about each row that gets kept.

Other that that, nothing occurs to me.

I can't initially think of an easy way to narrow the problem down
either...

Regards,

Simon


Re: javax.faces.ViewState contents?

Posted by Andrew Robinson <an...@gmail.com>.
The entire component tree is saved using saveState, I wasn't referring
to the saveState component, but ranter the saveState method on the
StateHandler interface

On 8/23/07, Ken McArthur <ke...@adsea.com> wrote:
>
> You mention what I believed to be true.  Since my simple page with a 70kb
> ViewState is not requesting saveState for anything, I suspect it must be
> something else that's being serialized.  Any ideas on what else it could be?
>
>
>
> On 8/23/07, Andrew Robinson <an...@gmail.com> wrote:
> > Anything that is returned from saveState on any object implementing
> > StateHolder is saved into the view state. (All UIComponents implement
> > StateHolder)
> >
> > On 8/23/07, Ken McArthur < ken.mcarthur@adsea.com> wrote:
> > >
> > > With client state saving, I was under the impression that only managed
> beans
> > > in session scope or used in t:saveState would be serialized into the
> hidden
> > > javax.faces.ViewState variable.  However, my application's creating
> > > ViewStates in pages with very simple forms that are almost 70 kb long!
> > >
> > > I'm thinking that if I serialized all managed beans in all scopes +
> resource
> > > bundle, it might come to about that.
> > >
> > > Do you know what specifically is stored in ViewState?  Put in other
> words,
> > > what is best way to architect application to minimize size of ViewState
> > > while still using client state saving?
> > >
> > > Thanks, I appreciate any advice,
> > > Ken
> >
>
>
>
> --
> 303-619-6607
> http://adsea.com

Re: javax.faces.ViewState contents?

Posted by Ken McArthur <ke...@adsea.com>.
You mention what I believed to be true.  Since my simple page with a 70kb
ViewState is not requesting saveState for anything, I suspect it must be
something else that's being serialized.  Any ideas on what else it could be?


On 8/23/07, Andrew Robinson <an...@gmail.com> wrote:
>
> Anything that is returned from saveState on any object implementing
> StateHolder is saved into the view state. (All UIComponents implement
> StateHolder)
>
> On 8/23/07, Ken McArthur <ke...@adsea.com> wrote:
> >
> > With client state saving, I was under the impression that only managed
> beans
> > in session scope or used in t:saveState would be serialized into the
> hidden
> > javax.faces.ViewState variable.  However, my application's creating
> > ViewStates in pages with very simple forms that are almost 70 kb long!
> >
> > I'm thinking that if I serialized all managed beans in all scopes +
> resource
> > bundle, it might come to about that.
> >
> > Do you know what specifically is stored in ViewState?  Put in other
> words,
> > what is best way to architect application to minimize size of ViewState
> > while still using client state saving?
> >
> > Thanks, I appreciate any advice,
> > Ken
>



-- 
303-619-6607
http://adsea.com

Re: javax.faces.ViewState contents?

Posted by Andrew Robinson <an...@gmail.com>.
Anything that is returned from saveState on any object implementing
StateHolder is saved into the view state. (All UIComponents implement
StateHolder)

On 8/23/07, Ken McArthur <ke...@adsea.com> wrote:
>
> With client state saving, I was under the impression that only managed beans
> in session scope or used in t:saveState would be serialized into the hidden
> javax.faces.ViewState variable.  However, my application's creating
> ViewStates in pages with very simple forms that are almost 70 kb long!
>
> I'm thinking that if I serialized all managed beans in all scopes + resource
> bundle, it might come to about that.
>
> Do you know what specifically is stored in ViewState?  Put in other words,
> what is best way to architect application to minimize size of ViewState
> while still using client state saving?
>
> Thanks, I appreciate any advice,
> Ken

Re: javax.faces.ViewState contents?

Posted by Andrew Robinson <an...@gmail.com>.
FYI, server state saving means all of that memory will be stored in
the server's java heap. So approx 70k * #users.

On 8/23/07, Ken McArthur <ke...@adsea.com> wrote:
> Mario,
>
> ViewStateDumper is awesome!  I get a large number of "#null?"s in output but
> everything else is as expected.  In my situation bottleneck is bandwidth;
> especially since ViewState is sent back to server and upload speeds are most
> always much slower than download speeds.  Compressed ViewState by adding the
> following to web.xml:
>
>   <context-param>
>
> <param-name>org.apache.myfaces.COMPRESS_STATE_IN_CLIENT</param-name>
>     <param-value>true</param-value>
>   </context-param>
>
> This cut ViewState down by about 1/5th.
>
> Thanks again to all.  I think I have good temporary solution but will look
> more into server side state saving.
>
> Ken
>
>
>
>
> On 8/23/07, Ken McArthur <ke...@adsea.com> wrote:
> > Great advise, I'll try it all and update board when I figure it out.
> Thanks.
> >
> >
> >
> > On 8/23/07, Mario Ivankovits <mario@ops.co.at > wrote:
> > > Hi!
> > > > With client state saving, I was under the impression that only managed
> > > > beans in session scope or used in t:saveState would be serialized into
> > > > the hidden javax.faces.ViewState variable.  However, my application's
> > > > creating ViewStates in pages with very simple forms that are almost 70
> > > > kb long!
> > > I've create a simple ViewState dumper which allows you to .. well ...
> > > dump the view state :-) ... as long as you do not compression or
> encryption.
> > > Just set the viewState variable to the content of the viewState in the
> > > HTML output.
> > > Maybe you can figure out what happens.
> > >
> > > Unhappily there is no information about which component added the data
> > > to the state, though, it might be a start anyway.
> > >
> > >
> > > import org.apache.commons.codec.binary.Base64 ;
> > >
> > > import java.io.ByteArrayInputStream;
> > > import java.io.IOException;
> > > import java.io.ObjectInputStream;
> > > import java.util.Collection;
> > >
> > > public class ViewStateDumper
> > > {
> > >     public static void main(String[] args) throws IOException,
> > > ClassNotFoundException
> > >     {
> > >         String viewState="";
> > >
> > >         byte[] viewStateData =
> > > Base64.decodeBase64(viewState.getBytes("US-ASCII"));
> > >         ObjectInputStream ois = new ObjectInputStream(new
> > > ByteArrayInputStream(viewStateData));
> > >
> > >         Object[] state = (Object[]) ois.readObject();
> > >         dumpState("", state);
> > >     }
> > >
> > >     private static void dumpState(String prefix, Object[] state)
> > >     {
> > >         for (Object object : state)
> > >         {
> > >             System.err.print(prefix);
> > >
> > >             if (object == null)
> > >             {
> > >                 System.err.println("#null?");
> > >             }
> > >             else if (object instanceof Object[])
> > >             {
> > >                 System.err.println(prefix + "array");
> > >                 dumpState(prefix + "    ", (Object[])
> object);
> > >             }
> > >             else if (object instanceof Collection)
> > >             {
> > >                 System.err.println(prefix + "collection");
> > >                 dumpState(prefix + "    ",
> ((Collection) object).toArray());
> > >             }
> > >             else
> > >             {
> > >                 System.err.print(object.getClass().getName());
> > >                 System.err.print(" ");
> > >                 System.err.println(object.toString ());
> > >             }
> > >         }
> > >     }
> > > }
> > >
> > >
> > > Ciao,
> > > Mario
> > >
> > >
> >
> >
> >
> > --
> >
> > 303-619-6607
> > http://adsea.com
>
>
>
> --
> 303-619-6607
> http://adsea.com

Re: javax.faces.ViewState contents?

Posted by Ken McArthur <ke...@adsea.com>.
Mario,

ViewStateDumper is awesome!  I get a large number of "#null?"s in output but
everything else is as expected.  In my situation bottleneck is bandwidth;
especially since ViewState is sent back to server and upload speeds are most
always much slower than download speeds.  Compressed ViewState by adding the
following to web.xml:

  <context-param>
    <param-name>org.apache.myfaces.COMPRESS_STATE_IN_CLIENT</param-name>
    <param-value>true</param-value>
  </context-param>

This cut ViewState down by about 1/5th.

Thanks again to all.  I think I have good temporary solution but will look
more into server side state saving.

Ken




On 8/23/07, Ken McArthur <ke...@adsea.com> wrote:
>
> Great advise, I'll try it all and update board when I figure it out.
> Thanks.
>
> On 8/23/07, Mario Ivankovits <mario@ops.co.at > wrote:
> >
> > Hi!
> > > With client state saving, I was under the impression that only managed
> >
> > > beans in session scope or used in t:saveState would be serialized into
> > > the hidden javax.faces.ViewState variable.  However, my application's
> > > creating ViewStates in pages with very simple forms that are almost 70
> >
> > > kb long!
> > I've create a simple ViewState dumper which allows you to .. well ...
> > dump the view state :-) ... as long as you do not compression or
> > encryption.
> > Just set the viewState variable to the content of the viewState in the
> > HTML output.
> > Maybe you can figure out what happens.
> >
> > Unhappily there is no information about which component added the data
> > to the state, though, it might be a start anyway.
> >
> >
> > import org.apache.commons.codec.binary.Base64 ;
> >
> > import java.io.ByteArrayInputStream;
> > import java.io.IOException;
> > import java.io.ObjectInputStream;
> > import java.util.Collection;
> >
> > public class ViewStateDumper
> > {
> >     public static void main(String[] args) throws IOException,
> > ClassNotFoundException
> >     {
> >         String viewState="";
> >
> >         byte[] viewStateData =
> > Base64.decodeBase64(viewState.getBytes("US-ASCII"));
> >         ObjectInputStream ois = new ObjectInputStream(new
> > ByteArrayInputStream(viewStateData));
> >
> >         Object[] state = (Object[]) ois.readObject();
> >         dumpState("", state);
> >     }
> >
> >     private static void dumpState(String prefix, Object[] state)
> >     {
> >         for (Object object : state)
> >         {
> >             System.err.print(prefix);
> >
> >             if (object == null)
> >             {
> >                 System.err.println("#null?");
> >             }
> >             else if (object instanceof Object[])
> >             {
> >                 System.err.println(prefix + "array");
> >                 dumpState(prefix + "    ", (Object[]) object);
> >             }
> >             else if (object instanceof Collection)
> >             {
> >                 System.err.println(prefix + "collection");
> >                 dumpState(prefix + "    ", ((Collection)
> > object).toArray());
> >             }
> >             else
> >             {
> >                 System.err.print(object.getClass().getName());
> >                 System.err.print(" ");
> >                 System.err.println(object.toString ());
> >             }
> >         }
> >     }
> > }
> >
> >
> > Ciao,
> > Mario
> >
> >
>
>
> --
> 303-619-6607
> http://adsea.com
>



-- 
303-619-6607
http://adsea.com

Re: javax.faces.ViewState contents?

Posted by Ken McArthur <ke...@adsea.com>.
Great advise, I'll try it all and update board when I figure it out.
Thanks.

On 8/23/07, Mario Ivankovits <ma...@ops.co.at> wrote:
>
> Hi!
> > With client state saving, I was under the impression that only managed
> > beans in session scope or used in t:saveState would be serialized into
> > the hidden javax.faces.ViewState variable.  However, my application's
> > creating ViewStates in pages with very simple forms that are almost 70
> > kb long!
> I've create a simple ViewState dumper which allows you to .. well ...
> dump the view state :-) ... as long as you do not compression or
> encryption.
> Just set the viewState variable to the content of the viewState in the
> HTML output.
> Maybe you can figure out what happens.
>
> Unhappily there is no information about which component added the data
> to the state, though, it might be a start anyway.
>
>
> import org.apache.commons.codec.binary.Base64;
>
> import java.io.ByteArrayInputStream;
> import java.io.IOException;
> import java.io.ObjectInputStream;
> import java.util.Collection;
>
> public class ViewStateDumper
> {
>     public static void main(String[] args) throws IOException,
> ClassNotFoundException
>     {
>         String viewState="";
>
>         byte[] viewStateData =
> Base64.decodeBase64(viewState.getBytes("US-ASCII"));
>         ObjectInputStream ois = new ObjectInputStream(new
> ByteArrayInputStream(viewStateData));
>
>         Object[] state = (Object[]) ois.readObject();
>         dumpState("", state);
>     }
>
>     private static void dumpState(String prefix, Object[] state)
>     {
>         for (Object object : state)
>         {
>             System.err.print(prefix);
>
>             if (object == null)
>             {
>                 System.err.println("#null?");
>             }
>             else if (object instanceof Object[])
>             {
>                 System.err.println(prefix + "array");
>                 dumpState(prefix + "    ", (Object[]) object);
>             }
>             else if (object instanceof Collection)
>             {
>                 System.err.println(prefix + "collection");
>                 dumpState(prefix + "    ", ((Collection)
> object).toArray());
>             }
>             else
>             {
>                 System.err.print(object.getClass().getName());
>                 System.err.print(" ");
>                 System.err.println(object.toString());
>             }
>         }
>     }
> }
>
>
> Ciao,
> Mario
>
>


-- 
303-619-6607
http://adsea.com

Re: javax.faces.ViewState contents?

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi!
> With client state saving, I was under the impression that only managed
> beans in session scope or used in t:saveState would be serialized into
> the hidden javax.faces.ViewState variable.  However, my application's
> creating ViewStates in pages with very simple forms that are almost 70
> kb long!
I've create a simple ViewState dumper which allows you to .. well ...
dump the view state :-) ... as long as you do not compression or encryption.
Just set the viewState variable to the content of the viewState in the
HTML output.
Maybe you can figure out what happens.

Unhappily there is no information about which component added the data
to the state, though, it might be a start anyway.


import org.apache.commons.codec.binary.Base64;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.Collection;

public class ViewStateDumper
{
    public static void main(String[] args) throws IOException,
ClassNotFoundException
    {
        String viewState="";

        byte[] viewStateData =
Base64.decodeBase64(viewState.getBytes("US-ASCII"));
        ObjectInputStream ois = new ObjectInputStream(new
ByteArrayInputStream(viewStateData));

        Object[] state = (Object[]) ois.readObject();
        dumpState("", state);
    }

    private static void dumpState(String prefix, Object[] state)
    {
        for (Object object : state)
        {
            System.err.print(prefix);

            if (object == null)
            {
                System.err.println("#null?");
            }
            else if (object instanceof Object[])
            {
                System.err.println(prefix + "array");
                dumpState(prefix + "    ", (Object[]) object);
            }
            else if (object instanceof Collection)
            {
                System.err.println(prefix + "collection");
                dumpState(prefix + "    ", ((Collection) object).toArray());
            }
            else
            {
                System.err.print(object.getClass().getName());
                System.err.print(" ");
                System.err.println(object.toString());
            }
        }
    }
}


Ciao,
Mario