Introduction to _javascript_ and WebObjectsFirst, let's revisit the Hello application created in Chapter 1, "A Web Objects Primer." We are going to return the greeting in the form of a _javascript_ pop-up window instead of a second page. Dynamically Vended _javascript_ Alert PanelDuplicate the Hello project and rename it DynamicHello by following the instructions in Chapter 1. Open Main.wo in WebObjects Builder. We are going to use an onLoad script to perform the _javascript_ alert. Add the following key to the Main page:
Name: onLoad
Type: String (java.lang.String)
As Variable: NO
Accessors: Only the Method returning the value
Now bind the onLoad key to the WOBody element. Because onLoad isn't a defined binding for WOBody (that is, you wouldn't see it listed in the WOBody Inspector) we need to add it to a new binding. From the binding drop down, select Connect to new Binding …. Enter onLoad into the Attribute field in the Inspector. This will bind the onLoad key to the custom binding onLoad of the <BODY> element. Copy the following lines into the onLoad() accessor: public String onLoad() {
String username = (String) valueForKeyPath("session.username");
String + username + "!');";
return (username != null) ? onLoad:null;
} |