Fujian...
Sorry I haven't gotten back to you sooner. I noted that you seem to have
solved the problem (Way to go!!), but I thought that you might appreciate
getting answers to your questions. I'm sure the information will help you
in the future.
> > Your Java code runs inside the CP Service process. Each CP may have one
or
> > more CP Workers (threads). Class instance variables can only be set and
> > used within one web event. A web event is the duration from the start
of
> > the page request (either load() or xxx_onWebEvent()) to the time that
the
> > results are returned to the browser. As requests come into the ND App
> > Server, the requests are distributed between the free CP Workers. Thus,
for
> > any given user/session, there's no guarantee that the same CP Worker
will be
> > used to answer every request.
>
> How about set it to static variable?
Static variables won't work because of the there's no guarantee that the
requests of multiple users will be processed by the same CP. So, UserA will
request a page and get results. Then UserB will request a page and get
results. UserB has now reset UserA's value. So when UserA needs the value
again, he will get UserB's value instead of his own.
> > What you're trying to do won't work because the user ID is being
generated
> > during one web event (page request) and the Insert_onWebEvent is being
> > processed during another. There's no guarantee that the same CP will
> > process the two requests, so you can't depend on any variable stored
> > locally. Even if you were lucky enough to have the same CP Worker
process
> > the two requests, you'd still have to worry about what other requests
were
> > processed in the interim.
>
> I created the UserID in onBeforeDataObjectExecuteEvent, and try to get it
in
> xxx_onWebEvent. Is the onBeforeDataObjectExceuteEvent a kind of
WebEvent?Is
> there any relationshiop between the so called Generic event, Html event,
and
> Java event?
I assume that you meant the this_onBeforeDataObjectExecuteEvent which is a
CSpDataDrivenVisualEvent (i.e. custom NetDynamics event) for the page.
NetDynamics categorizes its events into 3 groups:
Generic = Common events for HTML or Java pages created in ND
HTML = Events that occur only for HTML pages created in ND
Java = Events that occur only for Java pages created in ND
The onBeforeDataObjectExecuteEvent falls into the first category.
> The button I use is of type built-in(insert). When click it, I expect to
tirgger
> an onBeforeDataObjectExecuteEvent, inside which I can create userID
according to
> the user input information and insert all of them into a table. At the
same
> time, I would also like to take user to another page by this click, where
he can
> get the userID created for him. My problem is if I user this insert type
for the
> button, I can not get uer to another page. But if I change the button type
to go
> to another ND page, I can not trigger onBeforeDataObjectExecuteEvent.
One of the keys to successful NetDynamics development is understanding the
NetDynamics event order. If you're fortunate enough to take a NetDynamics
class, you'll get this type of information. If you had the class and didn't
get it, then your instructor should be shot! If you're not able to take the
class, then you're going to have a rather rough time. I seem to recall some
document about the event order in the ND docs, but I can't find it right
now. (And, since I've never been very impressed with the ND documentation,
I'm not sure that it would help you that much anyway.) So, I'll do what I
can for you in the few minutes that I have available. (When I teach ND,
this usually takes hours!)
First, let's go over some terminology. In ND, "web event" means two things.
First, it means the entire sequence of events between the time the page was
requested (either through a URL request or through a button/HREF click).
Second, it means the event caused by a button/HREF click. This duel termino
logy was REALLY confusing developers, so a distinction was made in the
training materials. The term "web event" refers to the former and "click
event" refers to the latter (even though the event handler for the
button/HREF click still contains the name "onWebEvent").
Let's look at the simplest case first: loading an ND page through a URL
request. Because no web event handler has been defined, ND will use the
load() event by default. Basically, this causes the event order for
building a page to be triggered. Unfortunately, I don't have time to go
into the complete event order right now. But the
this_onBeforeDataObjectExecuteEvent is part of that event order and will
execute once for each data object whose data fields are bound to display
fields in the page. (Note: the data objects whose data fields are bound to
repeated objects in the page are not included. Those are processed as part
of the event order for the Repeated.)
Now let's look at the more complicated case: When you click on a button on a
NetDynamics page, the click event which is defined for that button
(btnName_onWebEvent) is triggered. By default, the code for that event (as
generated through the Studio) looks something like:
int command = PROCEED;
command = doAction();
return (command)
The first line is pretty simple. All Generic and Html events for ND return
a int value which is a return code. The return codes are:
- PROCEED which means "Do whatever you were supposed to do next"
- SKIP which means "skip the remaining event order for the object
being processed
- STOP which means "Stop all processing for this data driven visual"
Now, when buttons and HREFs are defined in the Studio, you have a choice of
using a built-in action (Insert, Update, Prev, Next), a page transition
(load another ND page), etc. This defines what is supposed to happen next.
In your case, you've selected to use the Insert built-in action. Each
built-in action triggers a different sequence of events and actions. For
the Insert action, the values from the various display fields are retrieved
and placed in the data objects, the data objects are used to insert rows
into the database, and finally, the load() event for the page is called.
(ND does quite a bit with those 3 lines of code!)
So, if you added code to set a value in the
this_onBeforeDataObjectExecuteEvent, it wouldn't get executed until AFTER
the btnName_onWebEvent.
> Another thing I got confused is that how the return value of an event
processing
> affect the execution of other event processing? In my case, I set the
button
> type as built-in(insert) and use the default insert_onWebEvent(), then the
> userID created inside onBeforeDataObjectExecuteEvent can be inserted into
the
> table. But if I load some other page in the insert_onWebEvent(), and
return
> (nextPage.load(false)), I can not get any information inserted into the
table?
> Why?
See above for the return codes.
The situation you're describing is pretty common... you want an ND built-in
action AND an ND page transition to result from the same button click.
However, ND doesn't allow you to do that. You then have two options:
1. Define the built-in action in the Studio and then modify the button
event handler such that:
int command = PROCEED;
// do the built-in action for the Insert
command = doAction();
// load the next page
CSpPage nextPage = (CSpPage) getPage ("yadayada");
command = nextPage.load(false);
// stop processing of the default action
// (which reloads the current page)
return (STOP)
2. Define the page transition in the Studio and then modify the button
event handler such that:
int command = PROCEED;
// Execute all data objects for bound display fields in Insert mode
executeAllInsertingDataObjects();
// do the page transition
command = doAction();
return (command)
If you have a chance and are further confused about event orders and the
like, check out the archives of the ND forum through the ND site. Les Hill
posted a handy dandy project that, when executed, shows the event order
fairly well. (Search for Les Hill in the web forum search page.) Also, use
the debugger to put breakpoints in your code. The more you play with this
stuff, the easier it will get.
I hope that helps.
-- Grace
_________________________________________________________________________
For help in using, subscribing, and unsubscribing to the discussion
forums, please go to: http://www.netdynamics.com/support/visitdevfor.html
For dire need help, email: [EMAIL PROTECTED]