SaveState and restoreState for a tableRowGroup - how on earth do you do it?

Hi everyone!

A few of my fellow developers/posters and I have been trying to figure this out.

We're trying to save the state (ie page 3 of 12) of a data table when a user goes to another .jsp, so that when they return to the original .jsp, they can be returned to the same page (ie page 3 of 12) of the data table.

We firstly started trying to getFirst and setFirst for the tableRowGroup but found out that that's not the correct method to use.

Jetsons kindly researched this and found that we should be using saveState and restoreState.

I'm part of the way through the process but this is the first site we have developed using creator and I'm not all that sure about how to use these methods.

Firstly: I can't seem to get my page bean to implement StateHolder.... it's "not abstract and doesn't override setTransient (boolean) in StateHolder"...?

Secondly: When I try this code.......

Saving state on the button to the next page....

FacesContext context = FacesContext.getCurrentInstance();

Object[] state = (Object[]) tableRowGroup1.saveState(context);

getSessionBean1().setContext(context);

getSessionBean1().setTableState(state);

Restoring state in the perender....

FacesContext context = getSessionBean1().getContext();

Object[] state = (Object[]) getSessionBean1().getTableState();

tableRowGroup1.restoreState(context, state);

I get the following error...

[#|2006-10-13T11:35:32.986+0100|INFO|sun-appserver-pe8.2|javax.enterprise.syste m.container.web|_ThreadID=20;|WebModule[/shop121006]In the came from enlargement if|#]

[#|2006-10-13T11:35:32.991+0100|SEVERE|sun-appserver-pe8.2|javax.enterprise.sys tem.container.web|_ThreadID=20;|WebModule[/shop121006]null

java.lang.IllegalStateException

at com.sun.faces.context.FacesContextImpl.assertNotReleased(FacesContextImpl.java: 382)

at com.sun.faces.context.FacesContextImpl.getApplication(FacesContextImpl.java:120 )

at com.sun.faces.el.ValueBindingImpl.restoreState(ValueBindingImpl.java:412)

I realize that I am probably on the wrong track but can't find any information about this.

Any help very much appreciated,

Emma

Edited by:

EmmaWykes - to make more sense.

[2363 byte] By [EmmaWykes] at [2007-11-26 10:46:18]
# 1

I did not try and not sure but couldnt you try to reget the context when restoring the state.

The context in session bean is related to previous request.

Saving state on the button to the next page....

FacesContext context = FacesContext.getCurrentInstance();

Object[] state = (Object[]) tableRowGroup1.saveState(context);

getSessionBean1().setContext(context);

getSessionBean1().setTableState(state);

Restoring state in the perender....

FacesContext context = FacesContext.getCurrentInstance();

(instead of)

//FacesContext context = getSessionBean1().getContext();

Object[] state = (Object[]) getSessionBean1().getTableState();

tableRowGroup1.restoreState(context, state);

akif

maolcay at 2007-7-7 2:58:29 > top of Java-index,Development Tools,Java Tools...
# 2
I tried it. It does not throw an exception.Even if it restores the component, the first property is overriden again after preender.akif
maolcay at 2007-7-7 2:58:29 > top of Java-index,Development Tools,Java Tools...
# 3

When I first saw this I thought it would be a 5 minute problem...

I expected that binding the TableRowGroup's first property to an integer property in the SessionBean would solve the problem. This didn't work. So eventually after about an hour of messing around I got this far:

I setup an integer SessionBean property. I added a forward and backward button. I set action handlers for the buttons doing this:

getSessionBean1().setTableStateHolder(getSessionBean1().getTableStateHolder()+tableRowGroup1.getRows())

The backward button does the opposite.

The pre-render sets the tableRowGrougp's first property to the sessionbean property. I did this also in the init.

This does not work because when you navigate back to the table you are on page 1. HOWEVER when you hit the forward / backward button you do wind up on the correct page.

The behaviour is reminisicient of the lifecycle issue caused by JSP properties overriding the properties set in init. But the JSP does not have anything set for the TableRowGroup's first property.

I've given up but I hope the above gives you some ideas on what to try next.

yossarian at 2007-7-7 2:58:29 > top of Java-index,Development Tools,Java Tools...
# 4

Ok I didn't really give up: update on both init and first pre-render the TableRowGroup's dataSource has zero row count. Suspicious. The following works:

Removed the sourceData property from the tableRowGroup:

<ui:tableRowGroup binding="#{Page2.tableRowGroup1}" id="tableRowGroup1" rows="10" sourceVar="currentRow">

Added the following to both the init and pre-render

tableRowGroup1.setSourceData(xyzDataProvider);

tableRowGroup1.setFirst(getSessionBean1().getTableStateHolder());

And I manipulate TableStateHolder with button components as described earlier.

Still for you to do: figure out how to get the built in pagination controls to transfer the first property to the sessionbean holder. Then dispense with the makeshift buttons.

All testing done with VWP by the way.

I suspect someone who understands the lifecycle better than I do may be able to file a bug on this.

yossarian at 2007-7-7 2:58:29 > top of Java-index,Development Tools,Java Tools...