dev@javaserverfaces.java.net

State Saving

From: Mark Collette <mark.collette_at_icesoft.com>
Date: Thu, 11 Sep 2008 11:55:00 -0600

Can someone explain something about state saving to me? This is rom
HtmlColumn:

    private Object[] _values;

    public Object saveState(FacesContext _context) {
        if (_values == null) {
            _values = new Object[3];
        }
        _values[0] = super.saveState(_context);
        _values[1] = footerClass;
        _values[2] = headerClass;
        return _values;
    }

    public void restoreState(FacesContext _context, Object _state) {
        _values = (Object[]) _state;
        super.restoreState(_context, _values[0]);
        this.footerClass = (java.lang.String) _values[1];
        this.headerClass = (java.lang.String) _values[2];
    }


Why make _values be an instance field, instead of just allocating it on
the stack? Won't the component tree be blown away, so that _values
isn't being reused, anyway? And if the component tree did stick around,
wouldn't the standing memory requirements go up, with all these Object[]
sticking around?

- Mark Collette