Tuesday, 4 September 2012

Hi this toutorial will help full for startup in grails created by NaveenRaju

Part1:



1 How to Install Grails In windows and linux OS:

Step1: 



Download Grails from folloing link   Download Grails  


Step2:


Before installing Grails you will need as a minimum a Java Development Kit (JDK) installed version 1.6 or above. appropriate JDK for your operating system, run the installer, and then set up an environment variable called JAVA_the location of this installation.

Step3:


*Set the GRAILS_HOME environment variable to the location where you extracted the zip
 On Unix/Linux based systems this is typically a matter of adding something like the 

 "GRAILS_HOME=/path/to/grails"  to your profile

*On Windows this is typically a matter of setting an environment variable

  "Computer/Advanced/Environment Variables"


Step4:


Then add the bin directory to your PATH variable:

On Unix/Linux based systems this can be done by adding export PATH="$PATH:$GRAILS_HOME/profile


On Windows this is done by modifying the Path environment variable
 Computer/Advanced/Environment Variables


Step5:


Check ur Grails Is installed properly and it is working corectly or not

click on start button go to run type cmd



C:\>grails -version


Grails version: 2.1.0

C:\>grails help



now  start Devolopment:




Grails Commands:


They are 9 basic commands we use in Grails while Devolopment

grails create-app Creates a Grails application for the given name
grails create-domain-class Creates a new domain class
grails generate-all Generates a CRUD interface (controller + views) f or a domain class
grails install-plugin Installs a plug-in for the given URL or name and version
grails create-controller Creates a new controller
grails interactive Starts Grails CLI (script runner) in interactive mode.Keeps the JVM running between grails comman ds for faster script execution.
grails console Load the Grails interactive Swing console
grails run-app grails [environment]* run-app - Runs a Grails app lication




Creating Programs Using Controller :



1 Hello World Program




Step1: Create Grails Application by typing folloing command in commandprompt

           
           grails create-app ApllicationName

ie: grails create-app HelloWorld




       
            

step2: create controller 


ie grails create-controller Hello1


     step3: open following ling and type following code


          C://HelloWorld/grails-app/controllers/helloworld/Hello1Controller.groovy
      


package helloworld

class Hello1Controller {

    def index() { 



render("Hello World")



    }
}




step:4 go to cmd prompt and run the application by typing 


  grails run-app
    step5: Open any Browser in Adderss Bar Browose to server which is specified on command prompt
                ie:   http://localhost:8080/HelloWorld
                               

step6: click on the link helloworld Hello1Controller

            




step7: if u what to off the server then go to cmd prompt and press Ctrl+c







2 With Out having link in grails home Page how to view result in controller


step1: grails create-app Naveen 
step2: grails create-controller WithOutLink



step3:open folloing link and type the folloing code

          c://Naveen/grails-app/naveen/WithOutLink.groovy


package naveen

class WithOutLinkController {

    def index() { 
    }

def raja={

render("Hi to all")
}

}


step4: grails run-app




step5: go to Browser And Type


           http://localhost:8080/Naveen
           

step6: click the naveen WithoutLinkController

           then it will show folloing error report

step7: so browse to folloing link

          http://localhost:8080/Naveen/withOutLink/raja
        

   step7:   In this  url
                http://localhost:8080/Naveen/withOutLink/raja    

               Naveen          -------->      GrailsApplicationName
               withOutLink    ------->      Controller    
                raja                -------->     Action         



   
How to eliminate above Error Report Means use redirection or code something else in index action in controller

3 using redierection in Controller :




step1:  create grailsapplication 


            ie grails create-app Naveen 
        


step2: create controller 

           ie: grails create-controller RedirectSearch


         



step3: open Folloing Link And write 


            C://Naveen/grails-app/controllers/naveen/RedirectSearchController.groovy
           


package naveen

class RedirectSearchController {

    def index() { 


redirect(action:raja)

    }




def raja={


render("Hi to all")

}


}



step4:Run This Application

            ie: grails run-app
          

step5: Open Any Browser and type 

              http://localhost:8080/Naveen




 step6: click the link  naveen RedirectSearchController


                                                                        
    step7: Off the Server by Pressing Ctrl+c
















































No comments:

Post a Comment