Hi Steffen,
I can imagine to write results on the serverside to a database, which
I can interrogate using ajax and add to the results through
javascript. then using ajax again look on the server if there are
newresults. This would work.
I imagine you'd experience some locking/concurrency issues with any number
of users attempting to write (and presumably delete - grow/shrink) rows into
the same section of a "scratch" table. Probably better throw in some sort of
house-keeping daemon as well to remove those orphaned rows that hang around
after ungraceful session exits.
Depends on your definition of "work" I suppose
Question: Is there a better way?
Answer: Yes
But you won't like it 'cos it doesn't involve HTTP let alone Ajax. You need
a connection-oriented, context-rich, middleware protocol that wasn't
designed from the ground up to serve static web-pages when dodgy/flaky
network connections were the de rigueur.
The example I'll show you processes a result-set from a server and populates
an option collection in a <select> list. Every time a row arrives from the
server a Record Count is clicked over for the user to see, the Select List
"grows" until 5 rows have been received, and then its scroll-bar diminishes
as more rows arise.
It is not the size of the data, but the time it will take the search.
Maybe I shouldn't use the term 'search', think of the result as
solutions. The solutions might take some time to calculate, and as the
soltions are coming in, I would like to show them on the client side,
so the user doesn't have to wait until everything is finished.
Exactly, Parallelism! The JavaScript browser client can be enriching or
adding-value to the raw data as it arives, relieving the server from that
additional processing burden, and making use of the grunt on the client
front-end. Having recently read about Flash's FABridge functionality, I'm
very excited about the possibility of watching a Flex Pie or Line-Chart grow
before the client's eyes as the Data Binding transaltes the dataset getting
pushed through from JavaScript!
In
fact, the user could stop the generation of solutions by sending a
request to the server.
You mean like a "Hot-Abort Button"? As is perfectly illustrated in the
following example: -
http://manson.vistech.net/t3$examples/demo_client_web.html
Username: TIER3_DEMO
Password: QUEUE
I'll post more demo instructions at the end of this but, to see the bit you
want in action, just enter an asterix "*" for the Queue Name and then click
the green "Get Job Info" button. You'll see that the <select> list is
populated from the server, one row/element at a time. I have tested this
with up to 3000 rows and scalability doesn't seem to be an issue! The one
performance problem I experienced was the tear-down of the old/previous
option-collection before populating the results from the next query. Thanks
to RobG, the problem was solved with DOM Node Cloning and Replacing.
All of the client source code can be found at:-
http://manson.vistech.net/t3$examples/
QUEUE_LOOKUP.HTML contains the code you'd be interested in specifically the
jobLookup() and getResponse() functions, although following the selectRef
and selectClone objects through the code could be worthwhile. The driving
Applet is CornuCopiae.java and the object definition can be found in
CornuCopiae.html. (The main Socket stuff being in Tier3Socket.java) NB: All
Applet Java code is application-neutral and completely reusable. No Java
coding "need" be done for applications 2 to N.
If you'd prefer someone to have Mugabe(esque) totalitarian control over your
server interaction then I'd suggest Silverlight. (Or Flash's Data Management
Services - "All client-resident data in sync" - Yeah right. But at least
with Flash (and obviously Java) you get the choice!)
Although my code is, at present, VMS-specific you could achieve similar
results with simple INETd server processes, if you dropped the authorization
and were happy with one server process per user.
Cheers Richard Maher
PS. The code doesn't automatically check for versions, but does work on
recent versions of Mac OS X Safari (1.5 JDK), Firefox, Windows Firefox and
IE 6 and 7, Opera, Linux and Firefox. You must have JavaScript enabled,
Applets enabled and a recent JVM. You also can't be behind a firewall that
bans outgoing connections unless you open up 5255.
Here's some of the functionality-catwalk highlights from the example: -
1) Full, one-time, context-specific, VMS User Authentication. No Cookies,
Session IDs, Password Caching or generic Work-Station or Browser
credentials! When you load the demo_client_web.html page into your browser,
a Java Applet is automatically activated that prompts the user for their VMS
Username and Password via a modal dialogue box. If authorization fails, the
"Access Denied" page will be displayed and VMS Intrusion Detection (in
accordance with the policy set out by your System Manager) will be enforced,
and Login-Failures is incremented in SYSUAF. Alternatively, if authorization
is successful (and you left the "Display Logon Confirmation" box ticked)
then a Welcome dialog box will be displayed detailing last login times and
the number of unsuccessful login attempts (if any). Login-Failures is now
set to zero and last non-interactive login time is set to the current time.
If you refresh this page, or move to a different page, then the server
connection is broken and you must be re-authorised before continuing to
access the Demo Queue Manager application.
2) A Hot-Abort button! After you have pressed the "Get Job Info" button
you'll notice that the "Abort Request" button becomes active and turns red.
(Actually you probably won't notice 'cos this query completes too quickly
You can edit the DEMO_UARS.COB code and change the value of the
DEBUG_DELAY field if you want to see your 3GL Interrupt routine in action.)
In this case the cancel-flag I've set in the AST routine is picked up in the
mainline code, resulting in the graceful termination of the loop that
controls "next queue" (or "next row") retrieval.
Also, if you look at the getResponse() function in query_lookup.html, you
will see how the chan.setTimeout() method has been deployed to provide an
erstwhile "blocking" socket Read with the ability to surrender the
event-thread for things like processing the Abort button and ticking over
the clock. (all of this, and much more, "infrastructure-code" is already
there and doesn't have to be re-invented)
3) Predictive text on the Queue Name field so that all matching VMS queues
are retrieved on-demand as the user types. As is now common-place with many
websites, a drop down select list of matching options is automatically
retrieved from the server and made available for the user to select from.
4) Result-set drill-down. Many database queries return a result-set of rows
for the user to scan through and possibly drill-down into for more detail.
I've provided a reasonably generic example of this, where all matching Job
Entries have been populated into a dynamic HTML select list. Once again the
user was able to see the select-list grow, the scroll-bar diminish, and
"Jobs Found" field tick over in real-time, whilst continually being
empowered (by the Abort button) to curtail the results at any time!
If you click on an entry in the Select List then the <frame> changes and the
entry_details.html page appears. See the parent.entry_details.getReady()
call in queue_lookup.html to see how the handover to the new frame takes
place. (Also see goBack() in entry_details.html to see how simply that
operation is reversed.)
The user is now free to move forward, back, first, last, refresh, and delete
queue entries, or return to the previous frame. (Thanks to the deployment of
the VMS Persona functionality, the user is only permitted to see those queue
entries that the Username they signed in under is permitted to see. They can
also *only* delete those entries that this username is allowed to delete.)
5) Floating <div>s. You'll see that any queue names are highlighted in bold
and italics; if you mouseover any of these fields when they are not blank
then the current status information for that queue will be retrieved from
the server and displayed in a quasi-popup DIV.
6) Local Result-Set Sort. If you click on the "header" or "first" row in the
Select List of queues, you will get a popup prompting you for a sort key. If
you select one, the contents of the Select List are sorted in the chosen
order. (Try enter "*" for the Queue Name and then clicking "Get Job Info" to
get some data worth sorting)