Grails Cookbook - A collection of tutorials and examples

Byte Array to String in Java

There are programming scenarios where we have a data in byte array that represents a String. This could be a case when we use a third party library to load data somewhere and the result is a byte array. In such cases, we may want to convert back the byte array to a String. Below are some examples on how to convert a byte array to String in Java.

Java String Array Declaration

An array is a basic and essential data structure in Java. It holds a fix number of values that can be easily manipulated. It is common to use an array of immutable objects in Java, such as a String. But before we can use a String Array, we must first be able to declare it. Below are some examples on how to declare a String Array in Java.

Grails 3 Vue.js AJAX Table Examples

With all the popular JavaScript framework, I believe that Vue.js stands out as a powerful yet easy to learn framework. Other popular JavaScript framework have high learning curve. It takes weeks to understand and write simple stuff. Vue.js is a breath of fresh air because it provides excellent features yet it can be learned within minutes. In fact, I have written the example in this tutorial in less than 1 hour and having no prior Vue.js background. Here is an example on how to write in Grails 3 and Vue.js an AJAX table that displays records of a database table in paginated form.

Grails 3 Vue.js Hello World Examples

The release of Grails 3 coincide with the growing popularity of more modern Javascript frameworks. Gone are the days where we mostly write code in gsp and jQuery. Frameworks like AngularJS, React, Ember and others are gaining popularity. For beginners, I highly recommend Vue.js because it is very easy to learn like Grails. A developer with some experience will be able to grasps how to use it in minutes. But as always, the hard part is in getting started. How can our single page application interact with our Grails 3 back end? Below are some basic examples for beginners. Here are some Grails 3 Vue.js Hello World Examples.

Grails Select Enum Values

It is more convenient that we use Enums in our domain classes rather than String, when we are really sure that Enum is the best representation of a property. Maintaining Strings and constants is just a pain. But it is common problem on how to create a form that accepts Enum values. Below is an example on how to use Select Tag inGrails to choose from Enum values.

Convert String to Enum in Groovy

When programming in Grails, sometimes we get a String value that we wish to transform to an Enum. For example, when usually get String value from data passed from form or url parameters. Since Groovy 1.7.6, it is now easy to transform a String into a Enum value. Below are some examples:

Groovy SQL Delete Operation Examples

When a record in a database table is not needed anymore then we may want to delete it. There are two ways of deleting a record. One is called logical delete where the record is still in the table but a marker was set in one of the column to tell the application that uses the table to ignore it. The second one is called physical delete where we really delete the record in the databases. SQL provides the delete statement for physical delete. Below are examples on how to perform delete operation using Groovy SQL.

Groovy SQL Update Operation Examples

There are instances when data on a record should be modified. SQL provides update statements for this purpose. Below are examples on how to perform update operation using Groovy SQL.

Groovy SQL Read Operation Examples

Reading data from database tables is one of the most common task in programming. For RDBMS servers that supports SQL, we can use SELECT statements for this purpose. Below are some examples on how to read data from database tables using Groovy SQL.

Groovy SQL Insert Operation Examples

Another common operation when working with database is inserting data. This is simple to achieve using SQL's insert statements. Below are some examples on how to insert data to a database table using Groovy SQL.