Error message: Can not set Integer field to java.lang.Class - grails-2.0

I was running in some strange error message while defining a domain-model in Grails and applying a constraint to an integer variable.
package example
class Ip {
String inetAddress
String DNS
Integer Points
String toString(){
"${inetAddress}"
}
static constraints = {
inetAddress()
DNS()
Points(nullable: true)
}
}
This created the following error message when starting the application
Message:Can not set org.springsource.loaded.ISMgr field example.Ip.r$fields to java.lang.Class

Changing the variable definition from
Integer Points
to
Integer points
solved the problem.

Related

nullable environment variables in Symfony

I know that env variables are string only. Symfony 3.4 supports env variables type casting.
Is there a way to pass null value through int validator?
.env
DATABASE_PORT=
#I also tried DATABASE_PORT=null, DATABASE_PORT=~
parameters.yml
app.connection.port: '%env(int:DATABASE_PORT)%'
#I also tried env(?int, env(int?
I'm getting an error: "Non-numeric env var "DATABASE_PORT" cannot be cast to int." or "Invalid env(?int:DATABASE_PORT) name: only "word" characters are allowed."
In yml there are ~ or null signs used to pass null, e.g:
app.connection.port: ~
Someone asked in the doc:
Is it, or will it be possible to define your own operator? Like
%env(myDecoder:API_PASSWORD)%, which will decrypt the environment
value into something usable.
class MyDecoder implements EnvironmentOperator {
public function resolve(string $value): string {
// magic stuff for decryption
return $value;
}
}
And the answer was:
yes, you just need to create a service that implements
EnvProviderInterface and tag it with container.env_provider.
You could create an operator to accept null as an int

SqlException with Creating User, after changing IdentityUser primary key from string to int

After I've followed this to change the type of Application User Id from string to int, I get SqlException if I try to create a new user.
The exact error is:
Cannot insert the value NULL into column 'Id' table 'DBNAME.dbo.AspNetUsers'; column does not allow nulls. INSERT fails. The statement has been terminated.
Line 208: };
Line 209:
Line 210: var result = await UserManager.CreateAsync(user, model.Password);
Line 211: if (result.Succeeded)
Line 212: {
Source File: C:\Projects\ProjectName\ProjectName\Controllers\MembersController.cs Line: 210
[SqlException (0x80131904): Cannot insert the value NULL into column 'Id', table 'DBNAME.dbo.AspNetUsers'; column does not allow nulls. INSERT fails.
The statement has been terminated.]
Here is the screenshot of AspNetUsers table design view:
I've looked at How to tell the primary key 'Id' of IdentityUser class is IDENTITY(1,1)?
and ASP.NET Identity - Error when changing User ID Primary Key default type from string to int AND when using custom table names but couldn't help me much.
Any help is very much appreciated.
Your problem that Identity is no longer generating a key for you - it did before.
For this problem to work you need to get the key automatically generated by a database. To get this done you need to apply the following attributes on your Id property in ApplicationUser class:
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public override int Id { get; set; }
And add another DB-migration to make sure the database knows what to do with this field.
UPD: oops. Just noticed that you already link to my identical answer. Does this not help?

Ionic 2 Sqlite Typescript errors

hi there i am trying out this SQLite example and I am getting these errors https://github.com/TeamClouders/Ionic-2-sqlite-demo,
Member 'db' implicitly has an 'any' type.
Member 'arr' implicitly has an 'any[]' type.
Parameter 'tx' implicitly has an 'any' type.
...
In https://github.com/TeamClouders/Ionic-2-sqlite-demo/blob/master/src/providers/sqlite.ts
Not sure what the issue is?
Cheers
UPDATE
thanks #yugantar kumar
i have seemed get the 'members' type set without errors:
public text : string = "";
public db:any = null;
public arr : any = [];
However I am still getting errors on the Params - not sure how to set the type of the parameters?
e.g
.transaction((tx) => {
tx.executeSql('CREATE TABLE IF NOT EXISTS Todo (id integer primary
key,todoItem text)');
#roshambo: You didn't define the type of these variables db, arr, tx in the code. Define the type of those variables in the code

Displaying 'Object' instead of parameter value for SpringMVC + i18n by using MessageSource

With SpringMVC, 'Object' name is displaying instead of parameter value. Below is my code.
msg("label.key.is.inactive", "Parameter");
label.key.is.inactive = key ''{0}'' is inactive. -- Present in properties file
#Autowired
private MessageSource messageSource;
protected String msg(final String msgKey,final Object... params){
return messageSource.getMessage(msgKey, new Object[]{params}, Locale.US);
}
Output:
Expected: key 'Parameter' is inactive.
Actual: key '[Ljava.lang.Object;#394a861' is inactive.
Can someone tell me what should be done to get the expected output.
Try this:
return messageSource.getMessage(msgKey, params, Locale.US);

Localization for "the value {0} is invalid" in case of int overflow

I've read answers about localization of validation errors by specifying DefaultModelBinder.ResourceClassKey, basically it's when entering string values in int field or not a datetime in datetime field.
But when I'm typing "111111111111111111111111111111" for an int field I get System.OverflowException and it looks like "The value '{0}' is invalid.".
Is there a way to localize (translate that message to other languages) that validation error in a way similar to other MVC-validation?
I had the same issue, and I finally managed to find the solution. Yes, that message can be localized, and luckily it's pretty easy when you figure it out.
You have to create a resource file and put it in the App_GlobalResources folder. You can call the file whatever you want, but I usually call it MvcValidationMessages.
Open the resource file and create a string with the name InvalidPropertyValue and write whatever message you want in the value field.
Now, open the Global.asax file and add the following line to the method Application_Start():
System.Web.Mvc.Html.ValidationExtensions.ResourceClassKey = "MvcValidationMessages";
"MvcValidationMessages" should of course be the correct name of the resource file you just created.
And voĆ­la! That's all there is to it. The message shown will now be your own instead of the default one.
I ended up overriding ModelBinder for int and supplying a localized error-message there:
public class IntModelBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
double parsedValue;
if (double.TryParse(value.AttemptedValue, out parsedValue))
{
if ((parsedValue < int.MinValue || parsedValue > int.MaxValue))
{
var error = "LOCALIZED ERROR MESSAGE FOR FIELD '{0}' HERE!!!";
bindingContext.ModelState.AddModelError(bindingContext.ModelName, string.Format(error, value.AttemptedValue, bindingContext.ModelMetadata.DisplayName));
}
}
return base.BindModel(controllerContext, bindingContext);
}
}
Then I simply registered it: ModelBinders.Binders.Add(typeof(int), new IntModelBinder()); and it now works fine.
P.S. sure, my localized errormessages are not hardcoded in model binder, this is just a simplified example :)

Resources