h:dataTable with multiple Windows in the same session

In order to display a collection of objects I use a standard JSF dataTable like this :

<h:dataTable value="#{visit.objectList}" var="rowObject" binding="#{actionBean.objectTable}" id="myTable" >

' visit ' is a SessionScope ManagedBean

' actionBean ' is a RequetScope BackingBean

' objectTable ' is an UIData property of actionBean.

The list is displayed page by page with a poolLenght of 10 entries ;

I use a commandLink on one column in order to select one Object and to display its properties in the next view :

<h:commandLink id="selectObj" action="#{actionBean.selectObject}">

<h:outputText value="#{rowObject.apps}" id="rowApp" />

</h:commandLink>

Here is my Java method ' actionBean.selectObject() ' to instantiate the selected object :

MyObject obj= (MyObject ) this.getObjectTable().getRowData();

Everything works fine untill I decide to display simultaneously the same list at a different page level in 2 different windows (within the same session : right click -> New -> Window) ;

After paging twice through the objectList in the second Window I come back to the first Window displaying the 1st page of the list and select the first rowObject .

Obviously, it is the first rowObject of the second Window that is displayed, not the one of the first Window.

This comes certainly from the SessionScope of managed Bean ' visit ' ;

But I could not manage to do a select in an objectList property of a requestScope managedBean ...

It seems that JSF re-initializes the IDs of dataTable rows at each page instead of incrementing the IDs ... Do I understand well or do I do something wrong ? Does a MyFaces dataTable provide a better solution ?

Thanks for support ...

lsalse

[1835 byte] By [lsalsea] at [2007-10-2 20:45:01]
# 1
If you don't give id's, JSF provides them for you. The only rule is that in the same page the id's are unique. So each time a page is requested, JSF begins from id 1 allways.
pringia at 2007-7-13 23:28:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Do you mean that I should set a static counter in my SessionScope object ' visit ' and assign it to my dataTable rows as dynamic IDs ?lsalse
lsalsea at 2007-7-13 23:28:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
NO. JSF do that automatically for you...
pringia at 2007-7-13 23:28:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

That's exactly the problem I am currently facing !!!! JSF does it for me, but does it wrong ... as far I understand the way it works !

THINK OF IT :

I display twice the same list in 2 different windows :

I FIRST list the first 10 entries of the dataBase in one window.

THEN, I list the next 10 entries of the dataBase in a 2nd window.

In order to be able to select one rowData, I put the list as a property of a SessionScope object ' visit ' ;

Then, when selecting the 1st row of the FIRST Window, JSF selects the 1st row of the SECOND Window, since this one is the result of the last request.

Even if the 1st objectList in SessionScope 'visit' has been overloaded by the 2nd request, JSF is still able to detect the rowIndex I am selecting in the DataTable of the 1st window, but it seems that JSF has switched the link to the UIData property 'objectTable' to the one of the second instance of RequestScope 'actionBean' ; JSF WOULD NOT PERSIST a different RequestScope 'BackingBean'for each request executed into a different Window.

Is JSF capable to instantiate (w. a distincitve ID) only one RequestScope 'ManagedBean' in the FacesContex ?

lsalse

lsalsea at 2007-7-13 23:28:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Why don't you have two datamodels?I don't understand well why do you need those two windows open and why you have the session bean...
pringia at 2007-7-13 23:28:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
my final users have strange habits ...regarding the use of SessionScope 'visit' the following tutorial could help understand : http://www.groundside.com/blog/content/DuncanMills/J2EE%20Development/2005/04/06/Drilldown_Edit_with_JSF.htmllsalse
lsalsea at 2007-7-13 23:28:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

We have a lot of Master/Detail tables with edit and we don't need any Session Beans.

If your pages worked with request scope bean you don't have that problem.

Have you tried doing the same with Tomahawk datatable? Have you tried jenia's components also?

Tomahawk's datatable have a property named persist that achives the same you are trying to do.

Regarding to your actual problem i don't know how to help you without seeing some code.

pringia at 2007-7-13 23:28:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Actually, a dataTable with command links and session scope must go hand in hand. Otherwise, there will be many potential problems.

Let's say, we have a dataTable:

<h:dataTable value="#{bean.employeeList}" ...>

To render the table, system will call getEmployeeList to get the data.

When a user clicks on a link, JSF attempts to re-create the view including the dataTable. getEmployeeList gets called again. This time, the returned list must be identical to the one used to render the table. Any difference can cause getRowData() method to fail or return wrong information.

The only solution (that I can think of) is to save the list or the managed bean containing the list property in session scope. This way, getEmployeeList keeps returning the same object.

The nearest alternative is to fetch the employees from the database every time getEmployeeList is called. Given the dynamic nature of data, noone can ensure that the same data in exact same order will be returned every time. The application will perhaps work fine in unit test environment, but, fail misreably in a more dynamically changing production environment.

This is a limitation of dataTable and one of the weakest point of JSF.

bibhas2a at 2007-7-13 23:28:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
We save the list in session.You can use Tomahawk's extended datatable, ans use the property preserveModel.
pringia at 2007-7-13 23:28:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...