Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Thursday, May 1, 2014

Developing Web Application Using Jaggery - Part 2

This is part 2 of a series of Jaggery tutorials. This post explains the syntax of Jaggery and how to develop a simple application using Jaggery. 

Please go through part 1, Developing Web Application Using Jaggery - Part 1, if you don't know about Jaggery, how to install it, run it etc.

 

Jaggery Syntax 

Jaggery file extension is .jag (like Java file extension is .java)

The following is the syntax of Jaggery.



Everything wrapped between <% %> is Jaggery code. It means that everything wrapped by <% %> runs on server.

The print(msg); method outputs a server side variable to the document.

.jag file can contains HTML code. The above code can be written as below, 


Create a directory "myApp" and save the above file as "index.jag" inside "myApp" directory. 

You have successfully created your first Jaggery App.

Let's deploy it. If you don't know how to deploy it, please refer to part 1 of this series.

Copy myApp directory to Jaggery deployment directory which is JAGGERY_HOME/apps. 

Let's start the server. If you don't know how to start the server, please refer to part 1 of this series.

Run sh JAGGERY_HOME/bin/server.sh ( JAGGERY_HOME/bin/server.bat in windows) command to start the server.

Let's access your myApp application. Point the browser URL to http://localhost:9763/myApp/. You will have your myApp up and running.

Let's learn some more built-in functions as we need those functions in our part 3 of this series.

request

This is an object which holds properties and functions regarding the HTTP request that the client made to the server.

For example, 

getRemoteAddr() - returns client's IP
getMethod() - returns type of request

For more information, please refer here


session

This is an object which holds properties and functions regarding the current session of a client.

For example, 
invalidate() - destroy the session

For more information, please refer to here. 

application

This is an object which holds properties which are global to the entire application instance.

For example, 
put('propName', value) - saves the value in the name of probName.

For more information, please refer to here.

I guess these are enough for next part of this series.

Develop a sample e-banking application using Jaggery




Developing Web Application Using Jaggery - Part 1


Introduction

This series of tutorials gives you a basic understanding of Jaggery framework and its capabilities in web application development. This tutorial, part 1, explains a little bit about Jaggery and how we can install it.

Jaggery is a newly designed server side JavaScript framework. You might know about JavaScript that is used at the client side to control the interaction of the user with the browser. It controls the browser, decorate the page, validate fields and do more and more stuff at the client side. At the server side, you normally have your logic in programming languages such as Java or PHP. So JavaScript runs at your computer's browser. Java runs at your server.


Isn't nice if we can write the server side logic using JavaScript? Jaggery is the solution. So you can develop a web application using JavaScript only.

 
Installation


Download the latest Jaggery here
Extract it (jaggery-0.9.0-SNAPSHOT.zip in my case) to a directory you prefer. Lets call it JAGGERY_HOME 


You will get the following folder structure.


├── apps
├── bin
├── carbon
├── etc
├── INSTALL.txt
├── LICENSE.txt
├── modules
├── README.txt
└── release-notes.html



That's it. You have installed it.

 

Running the Server


In your terminal, navigate to JAGGERY_HOME/bin directory which contains all the Jaggery execution scripts.
Run sh JAGGERY_HOME/bin/server.sh ( JAGGERY_HOME/bin/server.bat in windows) command to start the server. It starts the default carbon server bundled with the framework itself.


If your server starts successfully, you will get something like below in your terminal, 

 

Deploy Jaggery Applications

JAGGERY_HOME/apps is the deployment directory. Deploy (copy) your Jaggery application to the deployment directory. You can find some sample application in the deployment directory including the taskmaster application.

 

Accessing Jaggery Applications

Point the browser URL to http://localhost:9763/taskmaster
You will have a web application, taskmaster application, running.

So if you deploy an application $myApp, you can access your application @ http://localhost:9763/$myApp

 

Developing Jaggery Applications

Please refer Developing Web Application Using Jaggery - Part 2