I was wondering if there were any alternatives to this approach of
creating and populating arrays in each and every one of your components
- has anyone tried using reflection to do all of this automatically.
Surely for simple components one could easily run through its getter
methods and extract the values to generate the Object[] automatically.
Has anyone tried such alternative approaches?
Randahl
Cagatay Civici wrote:
The example you posted is the old code of UISaveState.
It's has a special usage.
Actually you don't need to care about valuebindings. There is a special
map that holds the valuebindings of a component in UIComponentBase,
this map is saved-restored in each postback.
On 10/18/06, Randahl Fink Isaksen <[EMAIL PROTECTED]> wrote:
Actually
I finally found an example on the web in which the restoreState
method actually takes responsibility of restoring the value bindings
internal state (see below) - can anyone confirm that this is the right
approach for properties with value bindings?
Randahl
public Object saveState(FacesContext context) {
Object values[] = new Object[2];
values[0] = super.saveState(context);
values[1] = getValue();
return values;
}
public void restoreState(FacesContext context, Object state) {
Object values[] = (Object[]) state;
super.restoreState(context, values[0]);
Object savedValue = values[1];
ValueBinding vb = getValueBinding("value");
if (vb != null) {
vb.setValue(context, savedValue);
}
Randahl Fink Isaksen wrote:
> I have been looking through a number of MyFaces components to see
how
> state saving was implemented, and it turns out that all the
components
> I have checked simply implement the saveState and restoreState
methods
> by returning an Object[] containing their private properties.
>
> But I keep asking myself "what about value bound properties?" If I
> have a component which has a property X which may be bound to
> #{someBean.someProperty} does that not mean that I need to restore
the
> value of the value binding?
>
> I would expect that restoreState should check if X was bound with a
> value binding and then restore the value of the value binding
instead.
> Could anyone please elaborate? Thanks.
>
> Randahl
>
>
>
|
- Re: How to saveState / restoreState for properties th... Randahl Fink Isaksen
-