Friday, 8 February 2013

HI THIS TOUTORIAL WILL HELP FULL FOR STARTUP IN GRAILS CREATED BY NAVEENRAJU

 Converting dynamic scaffold to MVC Patterns:

 step1: create  domain class Reports.groovy

package mvc

class Reports {



    String repotName
    String unit
    String owner

    static constraints = {
    }
}

 step2: create  controller ReportsController.groovy------->OWN MVC Pattern


package mvc

class ReportsController {

    def index() {


redirect(action:list,params:params)

    }





def list={


if(!params.max)params.max=10
[reports1:Reports.list(params)]

}



def show={

[reports:Reports.get(params.id)]

}




def save={


def reports=new Reports();
reports.properties=params
if(reports.save())
{

redirect(action:show,id:reports.id)


}


else
{

render(view:'create',model:[reports:reports])

}


}



def edit(Long id) {
        def reports = Reports.get(id)
        if (!reports) {
            flash.message = message(code: 'default.not.found.message', args: [message(code: 'demo.label', default: 'Demo'), id])
            redirect(action: "list")
            return
        }

        [reports: reports]
             
/*
    def sandeep=Reports.get(id)
    [sandeep:sandeep]*/
}


}

 step3: create View in path C:/MVC/grails-app/views/reports/list.gsp


<!doctype html>
<html>
    <head>
        <meta name="layout" content="main">
        <g:set var="entityName" value="${message(code: 'reports.label', default: 'Reports')}" />
        <title><g:message code="default.list.label" args="[entityName]" /></title>
    </head>
   




    <body>
       
            <ul>
                <li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
                <li><g:link class="save" action="save"><g:message code="default.new.label" args="[entityName]" /></g:link></li>
            </ul>
<table>
<thead>

<th>id</th>
<th>ReportName</th>
<th>BusinessUnit</th>
<th>Owner</th>
<th>
</thead>

<tbody>


<g:each in="${reports1}">
<tr>
<td class="actionButtons">
<span class="actionButtions">

<g:link action="show" id="${it.id}">${it.id}</g:link></td>

</span>
<td>${it.repotName}</td>
<td>${it.unit}</td>
<td>${it.owner}</td>

<td class="actionButtons">

</td>
</tr>
</g:each>
</tbody>
</table>



    </body>
</html>


 step4: create View in path C:/MVC/grails-app/views/reports/show.gsp

 

<!doctype html>

<html>

    <head>

        <meta name="layout" content="main">

        <g:set var="entityName" value="${message(code: 'reports.label', default: 'Reports')}" />

        <title><g:message code="default.list.label" args="[entityName]" /></title>

    </head>

    

    <body>

        

            <ul>

                <li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>

                <li><g:link class="list" action="list">List</g:link></li>

            </ul>

<div class="dialog">

<table>

<tbody>

<tr class="prop">

<td valign="top" class="name">id</td>

<td valign="top" class="value">${reports.id}</td>

</tr>

<tr class="prop">

<td valign="top" class="name">ReportName</td>

<td valign="top" class="value">${reports.repotName}</td>

</tr>

<tr class="prop">

<td valign="top" class="name">Unit</td>

<td valign="top" class="value">${reports.unit}</td>

</tr>

<tr class="prop">

<td valign="top" class="name">Owner</td>

<td valign="top" class="value">${reports.owner}</td>

</tr>

<fieldset class="buttons">

                    <g:hiddenField name="id" value="${reports?.id}" />

                    <g:link class="edit" action="edit" id="${reports?.id}"><g:message code="default.button.edit.label" default="Edit" /></g:link>

                    <g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />

                </fieldset>

</tbody>

</table>

</div>

</body>

</html>


 step5: create View in path C:/MVC/grails-app/views/reports/show.gsp

 

<html>
<body>

<g:form action="save" method="Post"

<div class="dialog">

<table>

<tbody>



<tr class='prop'>
<td valign='top' class='name'>
<lable for='repotName'>ReportName</lable>
<td>

<td valign='top' class='value ${hasErrors(bean:Reports,field:'repotName','errors')}'>

<input type="text" name="repotName" value="${reports?.repotName?.encodeAsHTML()}" />
</td>
</tr>









<tr class='prop'>
<td valign='top' class='name'>
<lable for='unit'>Unit</lable>
<td>

<td valign='top' class='value ${hasErrors(bean:Reports,field:'unit','errors')}'>

<input type="text" name="unit" value="${reports?.unit?.encodeAsHTML()}" />
</td>
</tr>




<tr class='prop'>
<td valign='top' class='name'>
<lable for='owner'>Owner</lable>
<td>

<td valign='top' class='value ${hasErrors(bean:Reports,field:'owner','errors')}'>

<input type="text" name="owner" value="${reports?.owner?.encodeAsHTML()}" />
</td>
</tr>

<div class="buttons">
<span class=""formButtons>
<input type="submit" value="create"></input>
</span>
</div>
</g:form>


</table>


</div>


</body>
</html>

 

 step6: create View in path C:/MVC/grails-app/views/reports/show.gsp

<%@ page import="mvc.Reports" %>
<!doctype html>
<html>
    <head>
        <meta name="layout" content="main">
        <g:set var="entityName" value="${message(code: 'demo.label', default: 'Demo')}" />
        <title><g:message code="default.edit.label" args="[entityName]" /></title>
    </head>
    <body>
        <a href="#edit-demo" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
        <div class="nav" role="navigation">
            <ul>
                <li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
                <li><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></li>
                <li><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></li>
            </ul>
        </div>
        <div id="edit-demo" class="content scaffold-edit" role="main">
            <h1><g:message code="default.edit.label" args="[entityName]" /></h1>
            <g:if test="${flash.message}">
            <div class="message" role="status">${flash.message}</div>
            </g:if>
            <g:hasErrors bean="${reports}">
            <ul class="errors" role="alert">
                <g:eachError bean="${reports}" var="error">
                <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message error="${error}"/></li>
                </g:eachError>
            </ul>
            </g:hasErrors>
            <g:form method="post" >
                <g:hiddenField name="id" value="${reports?.id}" />
                <g:hiddenField name="version" value="${reports?.version}" />
                <fieldset class="form">



                <%@ page import="mvc.Reports" %>




                </fieldset>
                <fieldset class="buttons">


                    <g:actionSubmit class="save" action="update" value="${message(code: 'default.button.update.label', default: 'Update')}" />




                    <g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" formnovalidate="" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />



                </fieldset>
            </g:form>
        </div>
    </body>
</html>
 

 

 step7: create View in path C:/MVC/grails-app/views/reports/list.gsp

<!doctype html>

<html>

    <head>

        <meta name="layout" content="main"/>

        <title>Welcome to Grails</title>

        <style type="text/css" media="screen">

            #status {

                background-color: #eee;

                border: .2em solid #fff;

                margin: 2em 2em 1em;

                padding: 1em;

                width: 12em;

                float: left;

                -moz-box-shadow: 0px 0px 1.25em #ccc;

                -webkit-box-shadow: 0px 0px 1.25em #ccc;

                box-shadow: 0px 0px 1.25em #ccc;

                -moz-border-radius: 0.6em;

                -webkit-border-radius: 0.6em;

                border-radius: 0.6em;

            }

            .ie6 #status {

                display: inline; /* float double margin fix http://www.positioniseverything.net/explorer/doubled-margin.html */

            }

            #status ul {

                font-size: 0.9em;

                list-style-type: none;

                margin-bottom: 0.6em;

                padding: 0;

            }

           

            #status li {

                line-height: 1.3;

            }

            #status h1 {

                text-transform: uppercase;

                font-size: 1.1em;

                margin: 0 0 0.3em;

            }

            #page-body {

                margin: 2em 1em 1.25em 18em;

            }

            h2 {

                margin-top: 1em;

                margin-bottom: 0.3em;

                font-size: 1em;

            }

            p {

                line-height: 1.5;

                margin: 0.25em 0;

            }

            #controller-list ul {

                list-style-position: inside;

            }

            #controller-list li {

                line-height: 1.3;

                list-style-position: inside;

                margin: 0.25em 0;

            }

            @media screen and (max-width: 480px) {

                #status {

                    display: none;

                }

                #page-body {

                    margin: 0 1em 1em;

                }

                #page-body h1 {

                    margin-top: 0;

                }

            }

        </style>

    </head>

    <body>

        <a href="#page-body" class="skip"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>

        <div id="status" role="complementary">

            <h1>Application Status</h1>

            <ul>

                <li>App version: <g:meta name="app.version"/></li>

                <li>Grails version: <g:meta name="app.grails.version"/></li>

                <li>Groovy version: ${org.codehaus.groovy.runtime.InvokerHelper.getVersion()}</li>

                <li>JVM version: ${System.getProperty('java.version')}</li>

                <li>Reloading active: ${grails.util.Environment.reloadingAgentEnabled}</li>

                <li>Controllers: ${grailsApplication.controllerClasses.size()}</li>

                <li>Domains: ${grailsApplication.domainClasses.size()}</li>

                <li>Services: ${grailsApplication.serviceClasses.size()}</li>

                <li>Tag Libraries: ${grailsApplication.tagLibClasses.size()}</li>

            </ul>

            <h1>Installed Plugins</h1>

            <ul>

                <g:each var="plugin" in="${applicationContext.getBean('pluginManager').allPlugins}">

                    <li>${plugin.name} - ${plugin.version}</li>

                </g:each>

            </ul>

        </div>

        <div id="page-body" role="main">

            <h1>Welcome to Grails</h1>

            <p>Congratulations, you have successfully started your first Grails application! At the moment

               this is the default page, feel free to modify it to either redirect to a controller or display whatever

               content you may choose. Below is a list of controllers that are currently deployed in this application,

               click on each to execute its default action:</p>

            <div id="controller-list" role="navigation">

                <h2>Available Controllers:</h2>

                <ul>

                    <g:each var="c" in="${grailsApplication.controllerClasses.sort { it.fullName } }">

                        <li class="controller"><g:link controller="${c.logicalPropertyName}">${c.fullName}</g:link></li>

                    </g:each>

                </ul>

            </div>

        </div>

    </body>

</html>

 

 

 

 

 step8: grails run-app

http://localhost:8080/mvcDemo








 

 Demo3:Uploading a file and store it in Database


step1:create  Demo1 domainclass



package demo2

class Demo1 {

String name

 byte[] data1
static constraints = {
data1 maxSize: 1024 * 1024 * 2 // 2MB
}
}

step1:create  Demo1 controllerclass


package demo2

class Demo1Controller {

    static scaffold=Demo1
}



o/p:

                                       


















 

No comments:

Post a Comment