I have an existing application that is a front end application which retrieves all of its information from external Web Services. I want to re-create this application using the Grails framework, however the use case is a bit odd. Grails is Model driven. In this case I really have no Database tables. My data is received real time through a web service call. My question to the community is how would you go about implementing the following use case:
Employee Search:
HERE IS THE UNKOWN PART: What is the best way to take these results and fit them into the Grails model? In other words, I need to display a Data Grid of the results (Search Results). The grid should work like the Grails list action, allowing the user to sort on particular columns, pagination etc.
There is no one single way to create Grails applications. Often applications do make use of domain classes that provide easy access to data in relational database tables, but you can easily switch to a NoSQL datastore or even use no direct persistence like in your application.
The simple answer to your question is that you should just create non-persistent data classes in src/groovy
and src/java
that represent the data you're working with from your web service calls. You can still use Grails for its controllers and GSPs, taglibs, services (non-transactional of course since there won't be database access), and also take advantage of the many available plugins.
You shouldn't have to do much to use the standard generated controllers and GSPs to display data with sorting and pagination. The generation scripts do expect domain classes, but you can cheat a bit to get those generated (and of course you can always code stuff by hand). For example if you have a Person class in src/groovy/com/yourcompany, move it to grails-app/domain
:
package com.yourcompany
class Person {
String firstName
String lastName
}
Then run grails generate-all com.yourcompany.Person
and it will create the controller and its unit test, and the GSPs. Now move it back to src/groovy
and use it as you want. The GSPs don't expect domain classes, they just expect individual class instances or lists of instances.
You'll need to convert controller calls to stuff like person.save()
to use your web services instead, but much of the code should be reusable.
One thing you can take advantage of is validation. You can annotate your classes with @Validateable
and define constraints to take advantage of Grails validation for non-persistent classes - see the documentation for more details.