aspose file tools*
The moose likes JSF and the fly likes Unable to display current row in a datatable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Unable to display current row in a datatable" Watch "Unable to display current row in a datatable" New topic
Author

Unable to display current row in a datatable

vishnu bola
Ranch Hand

Joined: Jun 01, 2009
Posts: 32
hi ranchers,
iam a newbie to JSF and facing some problem h:dataTable Tag. The issue is that my dataTable should show up three rows with different data. But it displays three rows with same data(only last object retrieved from the database) . Please advise how to resolve this issue

My JSP
<h:dataTable id="AData"
var="comp"
value="#{company.dataList}"
cellspacing="0"
styleClass="co"
width ="100%"
rowClasses="topRow"

summary="This table visually organizes information and is used for layout only">

<h:column>
<f:facet name = "header"><hutputText value ="End Date" /></f:facet>
<hutputText value="#{companyadminbean.product.expDate}"/>
</h:column>
<h:column>
<f:facet name = "header"><hutputText value ="Reports" /></f:facet>
<hutputText value="#{companyadminbean.product.expDate}"/>
</h:column>

</h:dataTable>



Appreciate your help in advance
Rohit Boorugu
Greenhorn

Joined: Oct 06, 2009
Posts: 14
hey vishnu can you be more clear on what dataList is. is its an array of size 3. just want to see how your backing bean is.
vishnu bola
Ranch Hand

Joined: Jun 01, 2009
Posts: 32
Hi rohit,

This is the backing bean for the jsp:

import com.UserRecord
public class UserController {
ArrayList<UserRecord> dataList = new ArrayList<UserRecord>();

public UserController() {
this.populateDataList();
}

public void setDataList(ArrayList<UserRecord> dataList)
{
this.dataList = dataList;
}
public ArrayList<UserRecord> getDataList() {
return this.dataList;
}

public void populateDataList() {
UserRecord userrecord = new UserRecord();
ArrayList<Address> addresslist=new ArrayList<Address>(); // This array list is populated from the database

for (int i=0;i<addresslist.size();i++) {
Address address = (address)address.get(i);
userrecord.set(address);
dataList.add(userrecord);
}


My Model Bean:

public class UserRecord {
public Address address;

//getters and setters for address object

}

My JSP
<h:dataTable id="AData"
var="comp"
value="#{usercontroller.dataList}"
cellspacing="0"
styleClass="co"
width ="100%"
rowClasses="topRow"

summary="This table visually organizes information and is used for layout only">

<h:column>
<f:facet name = "header"><hutputText value ="End Date" /></f:facet>
<hutputText value="#{comp.Address.city}"/>
</h:column>

</h:dataTable>

Faces-config:
<managed-bean-name>usercontroller</managed-bean-name>
<managed-bean-class>com.UserController</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>


Now the issue i have is i get three 3 addresses from database ..i could see 3 rows on the screen but with the same data...(last address). I feel there is error in logic May be i have to create an arry or list of UserRecords. Not sure how to implement it.Please i need your help to get this work done.
Rohit Boorugu
Greenhorn

Joined: Oct 06, 2009
Posts: 14
There are a few thing.

1. in this piece of code
public void populateDataList() {
UserRecord userrecord = new UserRecord();
ArrayList<Address> addresslist=new ArrayList<Address>(); // This array list is populated from the database

for (int i=0;i<addresslist.size();i++) {
Address address = (address)address.get(i);
userrecord.set(address);
dataList.add(userrecord);
}

the reference "addresslist" consists information from the database. so why are you doing address.get() shouldn't it be (address)addresslist.get(i);

2. Are you sure that the actually data is different. I mean are addresses different. You can check it if you run the prog in debug mode and see what the actual data is step by step. I can tell you how to do this in eclipse.

3. As i don't have access to how addresslist is populated i cant say if that might be the problem.

Debugging step by step is the best process to know what your program is doing.

All the best on this buddy.
vishnu bola
Ranch Hand

Joined: Jun 01, 2009
Posts: 32
hi rohit,
Address address = (address)address.get(i); Sorry this it was a type.. i called called get(i) on addresslist only. Here is the code on how data is populated int this array list. i checked the sysout statements and i see 3 different objects getting populated. public ArrayList getAccessGroups(int adminUserID)
{

ArrayList<Address> result=new ArrayList<Address>();
try{

result= AccountDAO.getAddress(adminUserID); // based on rek this fethes some 3 addresses from DAO


System.out.println("size of list" + result.size());
for(int i =0;i < result.size();i++){
System.out.println(result.get(i));
}
} catch (Exception e)
{
e.printStackTrace();
}
return result;

}
The questions i have are

how can i create multiple userrecord objects because i feel that i am overriding the same object with different data in the loop. I cann't create an array as i don't know the exact size. i am not sure i can create one more list of type Userrecord. Please advise.

i don't know how to run eclipse debug mode. i will be thankful if you could provide me with any useful link.
 
jQuery in Action, 2nd edition
 
subject: Unable to display current row in a datatable