Grails Constraints

grails is framework developed in groovy framework which internally uses java to build the applications very quickly. I got chance to work on grails application. so i want to blog about the grails constraints.

As you know in any web programming language, we need to do the form level validations. which we can do it either at client level validation or server level validation
client level validations means, the entered data can not be send to server an d do the validation at the browser, To do this, we have lot of scripting languages like JavaScript or vb scripts.
For Server level validations, the entered data send to server and server checks for different validations that we define at domain level.
we can use java or .net languages to do domain level validations. Groovy uses the java language to do validations
Grails can define the domain level constraints

Grails can be defined the constraints validation on domain class on the following way

class Employee {
String eid
String name
String email
Integer sal
static constraints = { eid:unique,name:blank, email:email:true
}

}

In the Employee domain class, validation constraints are defined in Groovy on Grails. groovy constraints are defined with in block containing all the required validation configuration for this domain class.

i am listing out the following domain level constraints.


List of domain validation constrains available in groovy and grails
blank:-
blank constraint is to specify the member variable in domain can be null or not
usage is name blank: true/false

creditCard:- this is used to check the member variable is credit card
email:- email validator check is used to check correct valid email validation rules
inList :- to check the valid values between the list of values
To check for the set of valid values with in range
matches :- this used to compare with the regular expression
max :- checks for allowed maximum value
maxSize :- this specifies the maximum size
min :- this is minimum value that would not allow specified
minSize :- minimum value to allow
notEqual :- this checks for the value is not equal specified
nullable:- the member value is null able or not
range:- specifies the range of values
unique :- unique constraint specifies that where the variable is duplicate or not


The above validators are predefined validators that come with grails plugin framework, we can also define our custom validator using grails framework. The validators checks and validates on form as server side validator

Application servers and web servers two type of servers need to know in web application development in software world. Developer write the piece code,packs this code as war and deploy/host the code in

one of the web server or application server, then users of the application can access the features of the application from any where in the world

Web server tutorial:-


Webservers are used to generate the dynamic content as well as static content. Clients send the http requests, process the request and gives response back to the user. Web servers process the html content, images, stylesheets elements. Popular webserver are apache webserver and Microsoft IIS.
Webserver is hardware and software, machine which has IP Address assigned to domain name, for example, client browser request for wwww.domainname.com/index.html, webserver on that box request index.html content and give back the response to the browser. This communication from client to webserver is happening over http protocol defined by w3c org
web server is most basic server to know in web based application development. The application s are packed as folder as well as web archives developed in java, php or Microsoft net technologies. webserver is used for small scale projects.

Application Servers tutorial:-


Application Servers is a java server which provides different following set of reusable following services. Application servers are used mostly in N-tier based projects, in which webserver act as front controller for application servers. Application servers host the EJB projects in the form of ear i.e. enterprise archive structure which contains jars and war modules

1.Object lifecycle management:- This service is basic service in any application servers, and create a pool of objects, does garbage collection and share this objects states in among user sessions calls.
2. Connection pooling :- Provides pre created pool of connections to the different databases and manages the connections, returns the connections to the pool whenever the connections are not used by the applications
3. Security Management:- application servers provides different levels of securities including authorization and authentication with different providers like databases realms, text files, and different LDAP Providers. Provides security at domain object level, web resource level as well as web context level.
4.java messaging services:- Application servers provides in build java messaging services as well as integrated with different JMS providers like SUN MQ providers.
5. Transaction management:- To maintain the ACID properties for the application transaction, application servers integrate with JTA and ORM Transactions
6. Load Balance and clusters:- To accommodate the load on the servers, group of application servers act as node, connected with group of nodes and serve the response even one of the node in group of node fails.
7. Fault Tolerance: - application servers provide the 99.999 up time to provide the reliable application with 367X24 up time.

I have listed few services here, but there are more services provided by application servers.
Developers need not write the above services when developing any j2ee applications, and write his business functionality code and can reuse those above services

Difference between application server and webserver


Difference between Application server and web servers is a basic interview question on j2eee world.
application servers are used to provide the different business services as mentioned below, web servers provides receives the request and get the dynamic content and send the response to the client.
Application servers are used in large scale enterprise projects, web servers are used in small scale projects.
the architecture for application servers is N-tier node architecture where number of nodes are connected as clustered environment.
webserver can be used in 2 tier as well as n tier architecture, and act as front controller for n tier architecture


The following are the list of popular application servers in java

1.apache Tomcat
2.Cauche resin
3.BEA Weblogic later acquired by Oracle
4.Linux Jboss
5.IBM Websphere
6.SAP Netweaver WebAs 6.4
7.Oracle Application Server
6.Apache Geronima application server
List of popular web servers for webapplicaiton development

1. Apache web server
2. Microsoft IIS
Groovy on Grails is open source application framework build on java language using groovy scripting languages.
what is groovy framework:-

Groovy is scripting programming language which runs on java virtual machine. Groovy is a java module that has one dependency jar file.
Groovy is scripting framework for building applications on top of java. It will reduce lot of java code to write the applications and the files are saved with extension as .groovy. The syntax for groovy and java looks similar.

Grails Framework:-


Grails is java web application development framework for building rapid web applications. Grails are integrated with spring and hibernate technologies to develop the applications very quickly. In Grails, to story any model object, we don't define any configuration or much files to do crud on model. just by coding by convention approach, we can simplify the development and do our logic quickly.

Grails applications can be build by java developers as well as developers who has development experience easily.

Advantages of Grails framework:-


support for building web applications quickly without focusing on software conventions
Integrate with persistent orm frameworks like hibernate and other frameworks like spring
Provide riche templates build on Groovy server pages to build standard UI elements and MVC features
Good documentation and lot of companies are using these technologies
Learning framework is easy and building web applications with this framework is straightforward.
Generate code automatically based on templates.
Building new applications is very easy


Disadvantages with Grails:-

It is developed on java, learning curve is there for non-java developers
Integrating with existing custom frameworks is very difficult and complex.
There is time consuming process while compiling grails apps as Interpretation of the scripts and conversion to .class files is to be done.

Grails is integrated with maven for building grails projects.

Grails project code architecture
controllers – grails-app/controllers :- here we can write the groovy files for controller related code
domain – grails-app/domain Contains the list of groovy model objects with package structure

view - grails-app/views

has the list of gsp files which are groovy based server pages to display the UI elements. Groovy server pages are like java server pages with support of groovy scripting languages.

This is just basic idea that i got to know and blogged.

Please share your views on this.