OK -
I’ve been using Netbeans 6.1 now and its perfect, really brilliant. But I decided (why I don’t know) to update to the latest nightly release of 6.1. When I loaded up my HUGE project that I’m working into 6.1 it crashed good and proper. The whole application went crazy.
So what went wrong. Well I had loaded up the latest Woodstock components because I wanted to use the excellent Wizard Facility. Unfortunately when I upgraded I failed to realise that the version with Netbeans 6.1 is NOT the latest release. Thus my project was damaged.
Now - To make things faster when rebuilding, a lot of times I use a nice grid which connects through to a form to edit the record (you know the sort of thing)….
So to make things faster I wrote some stuff into the Session Bean so that I could move between pages and make sure I was referencing the right record.
Firstly creating a variable to store the record ID:
public BigInteger RecordID;
// note that .my database ID's are all BIGINTS
// Add a new row to a recordset and save the ID
public void AddDBRow(CachedRowSetDataProvider dba) {
RowKey ask=dba.appendRow();
dba.setCursorRow(ask);
RecordID=(BigInteger) dba.getValue("id");
}
// Get the current Grid Row and save its id
public void EditDBRow(CachedRowSetDataProvider dba,RowKey ask) {
dba.setCursorRow(ask);
RecordID=(BigInteger) dba.getValue("id");
}
// Set the data provider to the right place in the database for editing
// note that this will not work if your ID field is not a BIG INTEGER (which it should be in my opinion)
// So you might need to change it to new Long(xx)
public void LoadEditPage(CachedRowSetDataProvider dba) {
RowKey ask=dba.findFirst("id", RecordID);
dba.setCursorRow(ask);
}
Ok so these 3 routines can be called within a JSF page.
Add new record button above the grid.
getSessionBean1().AddDBRow(dataprovider)
Edit DB Row Button on the Grid.
getSessionBean1().EditDBRow(coursesDataProvider,tableRowGroup1.getRowKey());
Then in the INIT function of the edit page that is linked to from the ADD NEW button and the EDIT button
getSessionBean1().LoadEditPage(cachedRowSetDataProvider1); // The cachedRowSetDataProvider1 is hooked up to the Row set data provider Lastly When you save your record sometimes you MAY need to do a refresh() afterwards...e.g cachedRowSetDataProvider1.commitChanges(); cachedRowSetDataProvider1.refresh(); If you get a synchronisation error this will solve the problem - if not don't bother.