Query regarding inserting a new row at first row data table

hi all,

I have a doubt regarding the insertion of new row in data table.I am now using the following code

if (skillDataProvider.canAppendRow()){

RowKey rowkey = skillDataProvider.appendRow();

skillDataProvider.setCursorRow(rowkey);

String skillID=getSkilID();

skillDataProvider.setValue("Skill.SkillID", rowkey, skillID);

int rowID=Integer.parseInt(rowkey.getRowId());

tableRowGroup1.setFirst(rowID);

}

Its working fine.But this code gives me provision to add the data at the last of the table.I need it to be at the first row.I tried

RowKey rowkey=skillDataProvider.insertRow(skillDataProvider.getRowKey(String.valueOf(0 )));

but it shows some null pointer exception.Can anyone help me?

Thanks in advance

Sree

[801 byte] By [harisree] at [2007-11-26 9:07:16]
# 1
Try dataProvider.cursorFirst() before appending the row.
Sabir at 2007-7-6 23:21:59 > top of Java-index,Development Tools,Java Tools...
# 2
hi,Thanks Sabir for your reply.It adding the new row at last position now also.do you have any other solutions?Please help meThanks Sree
harisree at 2007-7-6 23:21:59 > top of Java-index,Development Tools,Java Tools...
# 3
Sree,Myabe in your query string for the table data provider set a ORDER for your main columns as descending, it might work.CheersDaniel
danielmundra at 2007-7-6 23:21:59 > top of Java-index,Development Tools,Java Tools...
# 4

hi daniel,

Thanks for the reply.I tried with that also.But it is not working.Can we use insertRow() for this.What i meant is

dataprovider.cursorFirst();

RowKey firstRow=dataprovider.getCursorRow();

RowKey rk=dataprovider.insertRow(firstRow);

But this returns a Null rowKey.Do you have any solution for this?Please help me

Thanks in advance

Sree

harisree at 2007-7-6 23:21:59 > top of Java-index,Development Tools,Java Tools...
# 5
Hi, harisree There are no first or last record in relational databases. Database server decides where place new row in table. If you need some order you mast provide set of fields for sorting purposes
AChervov at 2007-7-6 23:21:59 > top of Java-index,Development Tools,Java Tools...
# 6

Hi AChervov,

Thanks for your reply.But i think you didn't get my query right way.I am using a datatable componenet which is binded to a dataprovider in my application.When i insert a new row using appendRow() function it must add the new row in the first row if the data table.I need only display and don't bother about the actual database server stuff.do you have any solution for this?

Thanks in advance

Sree

harisree at 2007-7-6 23:21:59 > top of Java-index,Development Tools,Java Tools...
# 7

I think AChervov has the right idea here.

CachedRowSetDataProvider.canInsertRow(beforeRow) returns false, so you cannot insertRow().

Therefore, you'll need to control the sort order yourself. I'd add a sort field to the database. Then use TableRowGroup.setSortCrtieria() to control the table display order. Or commit the append to the database immediately and reselect (refresh) the provider (assuming the provider has the desired "order by").

dkible at 2007-7-6 23:21:59 > top of Java-index,Development Tools,Java Tools...
# 8
I am having the same problem, and I am pretty sure my problem doesn't relate to databases and their order, because my datatable is bound to a List, not directly to a table, and I get that List from Hibernate query. What should I do in order to get this working? It's really driving me
marcelotmelo at 2007-7-6 23:21:59 > top of Java-index,Development Tools,Java Tools...
# 9
Hi,Please check this code.Use some id to sort.and set the incremented id to the newly added rowSortCriteria [] sc = new SortCriteria[1];sc[0] = new FieldIdSortCriteria(some uniqueID, false);tableRowGroup1.setSortCriteria(sc);CheersSree
harisree at 2007-7-6 23:21:59 > top of Java-index,Development Tools,Java Tools...