grails view parameters bind with non domain class - grails

I want to bind view page params to non domain class(say *.java class).
Project projectInstance = new Project(params)
where Project is not Domain class, it is simply java class.
Does grails provide any plugin or any way to bind it to non domain class.
Thanks.

You cand try with bindData.
In controler:
Project project = new Project()
bindData(project, params)

Related

Which is the parent class for grails domains

Which class/interface is the parent for all the grails domains.
I just want to know which class actually executes save method of a grails domain
Let us suppose we have grails domain with name book
Book book = new Book("1")
book.save()
There is no save method in book class so where does it actually resides.
https://gorm.grails.org/6.0.x/api/org/grails/datastore/gorm/GormEntity.html
GormEntity is the parent for all domains classes.

Models not loaded by Glass Mapper

Could anyone tell me why the models that I have in an external library (referenced in my main project) can't be loaded by Glass Mapper?
I get something like this:
Type Test.Project.Models.Item has not been
loaded
The version of Glass Mapper is 2.0.11 and Sitecore has the version 7.2 (client's request).
Thank you
When you install Glass.Mapper using the Glass.Mapper.Sc.CastleWindsor it will automatically load classes configured with attributes from the current assembly, but if you want to load classes configured with attributes from another assembly. you have to add adding another SitecoreAttributeConfigurationLoader
public static IConfigurationLoader[] GlassLoaders(){
var attributes = new SitecoreAttributeConfigurationLoader("Project.Website");
var attributes2 = new SitecoreAttributeConfigurationLoader("Project.Models");
return new IConfigurationLoader[]{attributes, attributes2};
}

Where should Grails Command objects be placed in the project structure?

I have a class called LoginCommand in domain/my/package/name
class LoginCommand {
String emailAddress
String password
}
My question is why is a table be auto generated in my database for a ***Command object in grails? Are these command objects supposed to be placed ouside of /domain to avoid auto generation of a table by hibernate/orm.
They should not go in grails-app/domain; they are not domain classes. Place them in src/groovy. Alternatively, a common convention is to put the command class in the same file as the controller that uses it.
Take a look at the Convention Over Configuration section in the grails manual to get an idea of what goes where.

Inject field in a grails domain class dynamically

I have a problem in a grails application. My application use a plugin to generate some domain models, I need to add a field to one of those domain models and I don't have the source code. Is there a way to do it dynamically? For example using the GORM API the metaclass or something like that?
You could probably just extend the class from the plugin and add your field. That is a common thing to do with plugins like Spring Security Core.
class MyUser extends SecUser {
String phoneNumber
...
}

Using a grails/groovy class by reference

I'm trying to create my own CRUD controller in grails for the stuff that the scaffolding won't do.
Instead of maintaining code for a controller for each domain, I'd like to have one controller that can look after any domain for the generic CRUD calls.. as the only difference is the domain class name.
Using the example of domain class Job & Note
Instead of
Job.get(id)
Job.list()
def instance = new Job(params)
Note.get(id)
Note.list()
def instance = new Job(params)
I was thinking of
def someHandler = Job // configurable
someHandler.get(id)
someHandler.list()
def instance = new someHandler(params)
The first two static methods work fine (get, list) but creating a new instance does not.
Any pointers as to how to best do this.
Cheers
Call the default constructor using
def instance = someHandler.newInstance()
and the constructor for params using
def instance = someHandler.newInstance(params)
If you're not happy with the scaffolded controllers/views that Grails provides by default, and want to change them in a similar fashion for all domain classes, a better approach might be to simply edit the templates that are used to generate these controllers/views.
You can do this by running the script grails install-templates. This will create a number of files in the src/templates/scaffolding directory, each of which defines the template used to generate a scaffolded artifact.
Change these templates to create the controllers/views that you want. If you've already run grails generate-all for any domain classes, you'll need to run it again for those classes to update the existing scaffolding.

Resources