...
Every WebObjects application includes a Main component by default. The HTML file is mostly empty except for "Hello World." Likewise, the Java file contains very little. We will learn how to add methods and variables to the component by building a very basic calculator.
Let's start by editing the Main.java file.
Code Block |
---|
public double firstUserInput;
public double secondUserInput;
public double result;
|
Code Block |
---|
public WOComponent addResult(double firstUserInput, double sendUserInput) {
result = firstUserInput + secondUserInput;
return null;
}
|
Code Block |
---|
// Generated by the WOLips Templateengine Plug-in at Mar 19, 2008 11:00:05 AM
package your.app.components;
import com.webobjects.appserver.WOComponent;
import com.webobjects.appserver.WOContext;
public class Main extends WOComponent {
private static final long serialVersionUID = 1L;
public double firstUserInput;
public double secondUserInput;
public double result;
public Main(WOContext context) {
super(context);
}
public WOComponent addResult() {
result = firstUserInput + secondUserInput;
return null;
}
}
|
Figure 2-1 The Eclipse Toolbar with WOLips installed
...