One of the projects I’m working on is huge.
The java server faces I have are multiple tabs, tabs within tabs (oh it goes on) and I came accross a strange problem where although I had made sure the cacheddataprovider was pointing to the right place it seemed to just go to the first record.
String sMyAccountNo=getSessionBean1().sAccountNo;
RowKey ask=cachedRowSetDataProvider1.findFirst("Accountno",sMyAccountNo);
cachedRowSetDataProvider1.setCursorRow(ask);
This code looks up the selected customer and is run in the init() phase of the faces class. However, click more than 3 tabs and the findFirst stops working.
The fix which I’m not too happy about because it creates more overhead is to add a:-
cachedRowSetDataProvider1.refresh();
Before we do the findFirst.
Thus the code is
String sMyAccountNo=getSessionBean1().sAccountNo;
cachedRowSetDataProvider1.refresh();
RowKey ask=cachedRowSetDataProvider1.findFirst("Accountno",sMyAccountNo);
cachedRowSetDataProvider1.setCursorRow(ask);
Ok just a note here before some clever person decides to have a go at me for using text as a primary key - I didn’t build the database and I’d *NEVER* do that. I’ve inherited what is in my opinion one of the worst examples of database structures I’ve ever seen, but the problem is that the organisation that uses it is running 24/7 so I can’t really make the massive changes I would if I had the chance.
Now that refresh thing REALLY bothered me so I changed the code like this:-
RowKey ask=cachedRowSetDataProvider1.findFirst("Accountno",sMyAccountNo);
cachedRowSetDataProvider1.setCursorRow(ask);
if (!cachedRowSetDataProvider1.getValue("AccountNo").equals(sMyAccountNo)) {
cachedRowSetDataProvider1.refresh();
ask=cachedRowSetDataProvider1.findFirst("Accountno",sMyAccountNo);
cachedRowSetDataProvider1.setCursorRow(ask);
}
So here we see that I try the find first, if it works - cool - onwards we go, if not then we do the refresh to make sure I do have the right record. Slightly more elegant.
