|
|
||
Working with JavaScriptWe have already seen how to add JavaScript verifiers to click handlers in order to reduce client-server round trips and server load.Jaxcent also allows other mechanisms for working with JavaScript.
The method
execJavaScriptCode( "alert( \"Hello\" );", false, null );
or
execJavaScriptCode( "alert", false, new Object[]{ "Hello" } );
The arguments are specified as an Object-array, and besides
the primitive type-wrappers (Integer, Boolean etc) and String,
can also include Jaxcent HTML element objects e.g. HtmlInputText,
HtmlPara etc.
The second parameter is
In addition to Client-driven Jaxcent FrameworkIn Jaxcent, normally the program logic is driven from the server side. But parts of, or the entire framework, can be client-side driven as well.
Jaxcent provides the JavaScript function
Jaxcent provides the corresponding Java method
Exercise:
Create an HTML file Jstest.html, with the Jaxcent JavaScript
<SCRIPT LANGUAGE="JavaScript">
<!--
function identify( element )
{
oldColor = element.style.backgroundColor;
elementToReset = element;
element.style.backgroundColor = "red";
setTimeout( "resetIdentified()", 1000 );
}
function factorial( n )
{
if ( n < 2 ) {
return 1;
}
return n * factorial( n-1 );
}
var oldColor;
var elementToReset;
function resetIdentified()
{
elementToReset.style.backgroundColor = oldColor;
}
var iter = 1;
function callServer()
{
JaxcentServerRequest( "Test", "Calling", "Server", iter++ );
setTimeout( "callServer()", 10000 );
}
setTimeout( "callServer()", 10000 );
-->
</SCRIPT>
Add a FORM, add an INPUT TEXT field to the form, and two BUTTONs with an id each. The text for the first button is "Identify Text Field", the text for the second button is "Compute Factorial 5".
|
||
|