Need help getting DataProvider cursor methods to work in JSC

Hi, I'm a newbie to Creator as well as JSF. I'm using JSC Update 1. I've

worked through a couple of the beginning tutorials including "Performing

Inserts, Updates, and Deletes" without a problem. I'm now trying to

craft a simple jsf database form application on my own using the sample

travel database and I'm stuck!

I put text fields on the form corresponding to each of the 4 fields in

the PERSON table and bound them to the fields in the table which, on

examination, resulted in a CachedRowSetDataProvider (personDataProvider)

in Page1 and a CachedRowSetXImpl (personRowSet) in SessionBean1. I then put 4 buttons on the form (First, Previous, Next, Last) for record

navigation. Here is the code I put in the first two actions (the others are

the same except for the cursor methods):

public String btn_firstrec_action() {

try {

personDataProvider.cursorFirst();

} catch (Exception e){

error("cursorFirst failed: " + e.getMessage());

log("cursorFirst failed " , e);

}

return null;

}

public String btn_next_action() {

try {

personDataProvider.cursorNext();

} catch (Exception e){

error("cursorNext failed: "+ e.getMessage() );

log("cursorNext failed " , e);

}

return null;

}

etc.

When I run the application using the bundled app server I get strange

behavior when I click the navigation buttons. There are 6 records in the

table. The application opens up displaying the data for the first

record. Clicking "Next" takes me to record 2--so far so good. However,

with repeated clicks on "Next", "Previous", "First" the data displayed in

the form remains the same. If I click "Last" (personDataProvider.cursorLast(); ), the data from record 6 is rendered OK!

I worked a little in the debugger. I added a cursorChanging method and

put a break point in there. Then I watched the index attributes for rk1

an rk2 as I continued the execution. I had to hit Alt+F5 (Continue)

2 to 4 times on each button click depending on the action--4X

with "Next" and "Previous". For each button click the index values would

change at first to what logically seemed the correct values but

then snap back to 0 or 1 as I kept continuing depending on the sequence--

wierd to me.

I also tried configuring all the form fields in a virtual form with

"Participate" on for the text fields and "Submit" on for the buttons

with the same result (I was really "shooting in the dark" here!).

I'm obviously missing something here--this shouldn't be this difficult!

I have scanned through a lot of the excellent tutorials, articles and forum posts as well as some of the sample apps but haven't as yet found a similar example of using the DataProvider cursor methods which seems pretty basic to me but, I could have easily missed seeing what I needed.

Any help would be greatly appreciated--I'm really counting on this tool

to get an overdue project going so I'm somewhat desperate.

Thanks, Len Sisson

[3194 byte] By [sissonlh] at [2007-11-26 9:50:16]
# 1

This happened to me as well the first time I used the JSC (and I was a newbie in web). I believe it is because everytime you hit the button, actually the sequence of program will back to init(), button_action(), prerender(), destroy(). So, try to remember the last state of the cursor position using session variable. And then you put a code in the init() to move back to the last cursor position.

Check the sample program provided by JSC (SinglePageCrudForm). This sample demonstrate how to put a code in init(), destroy() in order to 'remember' the last position.

hope that helps

Message was edited by:

discusfish

discusfish at 2007-7-7 1:00:54 > top of Java-index,Development Tools,Java Tools...
# 2
Thanks--that gives me something to go on! I was already looking at the code in the example app you mentioned since I posted but had only noticed the use of "discardsubmittedvalues" for virtual forms. What you are suggesting makes more sense.Len Sisson
sissonlh at 2007-7-7 1:00:54 > top of Java-index,Development Tools,Java Tools...
# 3
You might also want to look at the the latter half of http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/dat aproviders.html which shows how to do what you want to do.
jetsons at 2007-7-7 1:00:54 > top of Java-index,Development Tools,Java Tools...
# 4
Hey y'all, just wanted you to know that the article suggested by jetsons did the trick--thanks!!!
sissonlh at 2007-7-7 1:00:54 > top of Java-index,Development Tools,Java Tools...