Is any package name restrictions applied in grails? - grails

I have created a Domain class called Action under package promotion
package promotion
class Action {
String name
String code
String address
static constraints = {
name blank:false
code maxSize:5
address nullable:false
}
}
Issue: Here my problem is I can not generate controller&views. And also I can not change default error messages from message property for my constraints
example: promotion.Action.name.nullable=Please enter the action name
Note: But if I change my package name "promotion" to something like "com.app.act" it works fine.

Try to make package name little brief. So it can be a good coding practice also

Related

Grails scaffolding, still can't process java8 localdateTime in edit forms, nor can it do Map property

I am using Grails v3.3.9, latest grails hibernate 8 and grails plugins in build.gradle, along with java8 plugin, fields plugin (didn't make any difference) and Hibernate 8.
compile "org.hibernate:hibernate-core:5.1.5.Final"
compile group: 'org.hibernate', name: 'hibernate-java8', version: '5.1.5.Final'
compile "org.grails.plugins:gsp"
compile 'org.grails.plugins:grails-java8:1.2.3' //java 8 features including datetime in GSP
compile 'org.grails.plugins:fields:2.2.10'
I've tried this on my Domain model which extends an abstract class with LocalDateTime
abstract class Agreement {
String contractReference
String status
LocalDateTime contractSignedDate
LocalDateTime lastUpdated //updated by framework
LocalDateTime dateCreated //updated by framework
static constraints = {
contractReference nullable:false
status nullable:false
contractSignedDate nullable:true
}
}
and concrete class here
class MaintenanceAgreement extends Agreement {
String level
Map category = [:] //p1 to p5 and sla details
//static belongsTo = [serviceProvider : OrgRoleInstance, maintainer: OrgRoleInstance]
// implemented as unidirectional many to one ! mag point to org
static belongsTo = [maintainer: OrgRoleInstance]
static constraints = {
level nullable:false
//serviceProvider nullable:true
maintainer nullable:false //ref to maintainer party
category nullable:false
}
}
If I have a record in Db from bootstrap with null column - grails just doesn't how any field holder for null entry. Go back to bootstrap and manually create a value, restart.
At least this time list and show rendering put an actual on the form
However when you go to create a new form (or the edit action) you get this. The contractSigned (localDateTime) has no editor, and lastly the domain model has a property category as a Map, and there is no editor for Map column.
This is a real problem. I can revert back to trying to use Date but that's a retrograde step really, and the platform suggests the new data time formats are supported. The Map column to think what my fallback for that might.
Am I missing something here that makes this work ? or do I have re raise as defect ?
I ran into this in previous 3.3.8 build here also with no resolution to data time issue
previous record
see also previous ask for feature here
make java new dates first class citizen in grails
Don't use LocalDateTime in you class for data type. You might not able to edit that. Use Date type instead. Then grails itself will provide you date-picker to add and edit as well. If you need to extract current date time in GSP you can use ${new Date() as value of that field.

Grails Scaffolding

I am recently working on grails and would like to know how to do more complex scaffolding
For example, if I want to Scaffold a class
class Book{
Author a
Publisher p
// ....
}
Author class
class Author{
String firstName
String lastName
// ...
}
Publisher class
class Publisher{
String name
String address
// ....
}
Now if I have a BookController
class BookController{
static scaffold = true;
}
I have a layout of
Author Publisher
However if I want a layout with
AuthorID AuthorFirstName AuthorLastName PublisherName PublisherAddress
I have looked through the http://grails.org/doc/latest/guide/scaffolding.html, however, I am unable to set it to the given property. I would like to know I am able to accomplish it? A tutorial would be helpful.
The scaffolding plugin within Grails is not designed to handle these types of complex views out of the box. You have a few options:
Use the install-templates command and modify the scaffolding templates to handle your needs.
Re-design your domain class to use embedded Author and Publisher. This will change the scaffolding output, but it also will change a lot more too. I wouldn't use this option unless you understand all the changes this will make to your domain model.
Generate the code using scaffolding then customize the output to suit your needs.
Of the three options presented here I would recommend the third as it makes the most sense to address the narrow scope of your issue.
You could also use transients. But transients aren't displayed by default.
You need to modify the templates and explicitly hide otherwise hidden fields using constraints i.e. id
NOTE: code below untested, for illustration purposes only.
//optional, but allows code completion in IDE ;-P
String authorName
String getAuthorName(){
return a.firstName + ' ' + a.lastName
}
static transients = [authorName:String]
static constraints = {
id(display:false)
}

Unique key parts not showing in Create Form Grails

I have following Domain Class -
class xyz {
String name
String version
String vclass
Date dateCreated
static constraints = {
version(blank:false)
name (unique: ['version'])
}
static hasMany = [ yz: Yz ]
}"
when i create a record for it, i don't see an option to enter version, only name and vclass. Why?
In Grails, version is a special property of Domain classes used for optimistic locking. Rename your property to something other than version. You can read more about this in the user guide.

Step by step process of using resource.resx files(created outside the project using class library) in asp.net mvc4

I am creating an application using mvc4. In my application i created the resource.resx file outside the project (but in one solution where my mvc application is also reside) in class library. I want to use the label name or validation message from resource.resx file.
Like:-
public class xyz
{
[Display(Name = "LBL_name", ResourceType = typeof(Resource.abcd.Resource1))]
public string Name1 { get; set; }
}
"LBL_name" is specified in Resource1.resx file. "Resource.abcd" is its custom tool namespace.
I added the reference of class library to my mvc application and set the properties of resource.resx as suggested in this link.
But it gives the following error
Cannot retrieve property 'Name' because localization failed.
Type 'Resource.abcd.Resource1' is not public or does not contain a
public static string property with the name 'LBL_name'.
I am not sure of using the resource.resx file correctly. Can someone guide me one this.
Open the file in the resource editor in VS and make sure the access modifier param is set to Public.

Property [] of class [] can not be null error in Grails

I am new to Grails and getting this error on two out of my three domains when I run the project on all the domains content. The domain the works is
class Location {
def scaffold = true
String company
String name
String address
static belongsTo=[company:Company]
static constraints = {
}
}
The domain that does not work is
class Report {
def scaffold = true
String title
String location
Date published
static belongsTo=[location:Location]
static constraints = {
}
}
I can not see the structural or syntax issue that is trowing the errors. I have been trying a variety of adds and subtracts and can not seem to find anything that address this error at a basic level. Again I have just started using Grails and Groovy
After doing the changes told by #araxn1d, you should also check the constraints. By default all properties are not nullable (that's why you're getting for example the error for the title property)
If you already have data in your database you have two options:
Update your database and set the correct values in each table or row
Set each property in the domain as nullable. For example
static constraints = {
title nullable:true
}
Are you creating a Report with no properties set? By default, Grails will check that all properties are not null. If you want to allow the user to leave a certain field undefined (null), then you have to explicitly tell Grails in the constraints map:
static constraints = {
propertyName nullable: true
}
Seems like error is in this line:
String location
location is String type, but should be Locationtype. The same as String company in Location domain should be Company company.
I think the problem is that you've changed the structure of the domain class after you generated the automatically created views/controller for the domain.
I fixed it by just deleting the offending domain along with the controller/views file and recreating them. I'm sure you could root through and find the offending code though.

Resources