Building and Running the hello Application
This section tells you how to build and run the hello application using NetBeans IDE 5.5.1 and the Ant build tool.
Building and Running the hello Application
in NetBeans IDE 5.5.1
- Select File→Open Project in NetBeans IDE 5.5.1.
- Navigate to <swdp.tutorial.home>/examples/phobos, select hello, and click OK.
- Right click on the hello application in the
Projects pane and select Run Project.
Enter your name into the field and click the button so that Duke can say hello to you.
- To stop the application, right click the hello application in the Projects pane and select Stop Phobos Runtime.
- If you want to create a WAR file of the application so that you can deploy it onto your web server or application server, right click the hello application in the Projects pane and select Export as Web Archive (WAR).
Building and Running the hello Application
with Ant
- Open a terminal prompt and navigate to <swdp.tutorial.home>/examples/phobos/hello.
- Enter ant and press Enter.
This will build and package the hello.war web application.
- Enter ant deploy and press Enter.
This will deploy hello.war to Application Server 9.1.
- In a web browser navigate to:
http://<server>:<server port>/hello/
Enter your name into the field and click the button so that Duke can say hello to you.
- To undeploy the application, navigate to <swdp.tutorial.home>/examples/phobos/hello and run ant undeploy.
- To delete the built application, navigate to <swdp.tutorial.home>/examples/phobos/hello and run ant clean.
Developing the Calculator Phobos Application Using the NetBeans IDE
In this exercise you create the Calculator Phobos application using NetBeans 5.5.1 IDE.
Building and Running the Calculator Phobos Application Project
Creating a New Phobos Application Project
After completing this task, you should have a new Phobos application project. The files main.ejs, index.js, and main.js should open in the Source Editor.
- Choose File > New Project.
- Select Scripting under Categories and Phobos Application under Projects. Click Next.
- Type Calculator for Project Name.
- Change the Project Location to any directory on your computer.
- Select No CSS Style for the CSS Layout and click Finish.
Creating a New Controller File
- Expand the Calculator project node and Application Directory node in the Projects window.
- Right-click the controller node and choose New > Phobos Controller.
- Type calculator for Controller File Name and click Finish. When you click Finish, calculator.js opens in the Source Editor.
Modifying the calculator.js Controller
File
- Define the calculator controller by adding
the following to calculator.js:
library.common.define(controller, "calculator", function() { }); - Enter the following calculator controller class
inside the brackets:
this.Calculator = function() { }; - Enter the following show method to the Calculator function:
this.show = function() { var firstOperand = invocation.session.firstOperand; if (firstOperand == undefined) { firstOperand = 0; } var secondOperand = invocation.session.secondOperand; if (secondOperand == undefined) { secondOperand = "add"; } var op = invocation.session.selectedOp; if (op == undefined) { op = "add"; } var total = invocation.session.total; if (total == undefined) { total = 0; } model = { total: String(total), selectedOp: op, firstOperand: firstOperand, secondOperand: secondOperand }; library.view.render("calculator.ejs"); }; - Enter the following compute method after the show method:
this.compute = function() { library.httpserver.onMethod({ POST: function() { var firstOperand = Number(request.getParameter("firstOperand")); var secondOperand = Number(request.getParameter("secondOperand")); var operator = request.getParameter("operator") total = ({ add: function(x,y) { return x+y; }, subtract: function(x,y) { return x-y; }, multiply: function(x,y) { return x*y; }, divide: function(x,y) { return y == 0 ? 0 : x/y; }, }[operator])(firstOperand, secondOperand); invocation.session.total = total; invocation.session.selectedOp = operator; invocation.session.firstOperand = firstOperand; invocation.session.secondOperand = secondOperand; library.httpserver. sendFound(library.httpserver.makeUrl("/calculator/show")); }, any: function() { library.httpserver.sendNotFound(); } }); } - Save your changes.

Previous