background preloader

Grails

Facebook Twitter

Example of template and taglib with grails. In this example I will show how templates and taglibs can be used to create components.Imagine that you are creating application for managing projects. When working with an application you are always working within a scope of project. So all the time you need to be able to change project you are working with. So excellent place for selection would be top of the each page within application. So lets go through steps creating such application. To create project in the command line type:grails create-app project_manager Then create Project domain class:grails create-domain-class Project Change the code of Project class so it looks this way: class Project { String title String description To generate controller and views for Project class use:grails generate-all project This should be enough to be able to start application with "grails run-app" and then open Se lets return to the problem.

Let start with the simplest solution. Content of this file should be: Enabling the AJAX Spinner in Grails. For standard page requests, browsers use an animated icon as an indicator to the user that the browser is waiting for the request to complete. However, for AJAX calls that are initiated via JavaScript in a separate thread the browser icon does not animate. So, typically the application developers use an animated icon within the page to notify the user the page is waiting for a request to complete. In an effort to simplify web development Grails automatically includes an animated spinner icon when using the Prototype or script.acolo.us AJAX frameworks.

To enable the Grails AJAX spinner you must include the Prototype or script.acolo.us JavaScript typically using the or tags. If you are using the default layout found in main.gsp, you can declare the Prototype or script.acolo.us inclusions in one of two places. <head><title>Make and Model</title><meta equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="layout" content="main"><g:javascript library="scriptaculous"/></head>

Nine Lessons from building a Grails / Flex / Flash website | Tomás Lin’s Programming Brain Dump. I just finished putting the finishing touches on phase one of our video and animation heavy Flash / Grails / Flex site. We spent about 2 months on this site, figuring out how to get Flex, Flash and Grails to work together nicely, and I thought I would share some of the lessons learned in this post. The application is a brochure-ware product that features rotating grills, and is back-ended by a Grails CMS. Grails was chosen over other toolkits like the Microsoft Community Server and Expression Engine because it provided the flexibility we needed to tackle a highly customized Flex RIA. Grails also allowed us to provide multiple views of our content for search engines and non-Flash customers.

Architecturally, our app is Grails — talks to —> Flex —-> talks to —> Flash —-> talks to —> Flex This is what I learned: Lesson 1: Spend time in your build and deploy tools – it’s worth it. Maven support for Grails is clunky, but it’s worth all the trouble to figure out. But it was worth it. Like this: Flex File Upload using Grails Backend. This file upload application is based off the one by Nocturnal at Coding Cowboys, a Flex client with a PHP backend. The client has been stripped down to it's core functions and PHP replaced with a Grails backend. The Grails backend is a file controller with an action defined: def upload = { if(request.method == 'POST') { Iterator itr = request.getFileNames(); while(itr.hasNext()) { MultipartFile file = request.getFile(itr.next()); File destination = new File(file.getOriginalFilename()) if (!

// Trigger an Event.COMPLETE event, notifying the Flex client response.sendError(200,'Done'); }} This is capable of uploading multiple files at once and can be tested using a view gsp: The Flex client has been pared down to 3 main functions, adding files to the upload list, removing them from the list and finally uploading the files to the server. First the imports, global variables and initializer: import mx.controls. The remove-files function: And lastly the UI: Links:Coding Cowboys: Flex upload component. Querying associations in Grails with HQL, Criteria and HibernateCriteriaBuilder.

A thing I was playing with today was many-to-many relationships in Grails to create a Tag Cloud. To create a Tag Cloud, I must have a set of key/value pairs, each with a label and a value of the label, which could look like this: ['Java': 5, 'Grails': 16, 'Groovy': 12] But to query this, I need to query a many to many relationship and produce the above result. This blog will describe how to do this with HQL, Criteria and the HibernateCriteriaBuilder. Domain My current domain looks like this: (This picture is unfortunately missing a Tag attribute in the Snippet class). As you can see, a Snippet can have multiple Tags, while a Tag can belong to multiple Snippets.

Options We have three options in this case HQLHibernate CriteriaHibernate Criteria using the HibernateCriteriaBuilder HQL The HQL version is not so hard (and neither are the other ones), but we have to start somewhere, so let's start with this one. To start at the end: the query looks like this: [["groovy", 1], ["io", 2], ["testing", 1]] Executing External Processes From Groovy. Goal: execute a program via a command line from groovy code Option 1: executing a string Gotchas: Take care if you wish to pass a quoted argument that contains white space – it will be split into multiple arguments, e.g.: """executable "first with space" second""".execute() will invoke executable with the following arguments: arg1 = "firstarg2 = witharg3 = space"arg4 = second In such a case, you may prefer to use one of the array or list of String variations, e.g ["executable", "first with space", "second"].execute() Option 2: using ant builder's exec task Ant has an exec task and it be accessed from the AntBuilder object The good thing is that you now have all the ant features at your disposal and Ant will not break up quoted args containing whitespace.

See also: Process Management Results of your search request can come from various sources: the Groovy website itself, the JIRA issues, the API documentation, as well as a few other interesting Groovy-related blogs. Directories. The Holy Grail 3 column Liquid Layout. Pixel widths. Cross-Browser. Equal Height Columns. Pixel dimensions of the holy grail layout In this layout the side column widths are in pixels and the centre page adjusts in size to fill the rest of the screen. Vertical dimensions are left unset so they automatically stretch to the height of the content.

Layouts that use pixel widths are great for images because you can make them fit perfectly within a column without gaps. The nested div structure I've colour coded each div so it's easy to see: The header, colmask and footer divs are 100% wide and stacked vertically one after the other. Try my Quirks-mode free and IE conditional comments free version of this layout. No CSS hacks The CSS used for this layout is 100% valid and hack free.

SEO friendly 2-1-3 column ordering The higher up content is in your page code, the more important it is considered by search engine algorithms. Equal height columns It doesn't matter which column has the longest content, the background colour of all columns will stretch down to meet the footer. No Images Safari. Framework Reference Documentation. Sandbox. Last updated by pledbrook 1 year ago Ideas Another test - please ignore. 汉语/漢語 This page is an ideas dump for proposed features. None of what is on here is likely to be implemented yet (or it may be but no documentation exists for it!). Potentially obsolete proposals: Graduates from the Sandbox Challenging problems and recipes There are many hard-to-solve problems in web application development. Developer discussion Grails 1.0 feature setTest SandBox Test Chinese: ??????.

Grails - jira.codehaus.org. Reference. Cookbook Examples. Recent Entries (Last 7 Days)