Mdriven Designer class attribute Allow Null=False not working - mdriven

I have a class named "Project" with attribute "Name" having type of String. I have changed it from Allow Null=True to False and then I have saved the model and restarted the WECPOF prototyper in xml mode. But it still allows me to create and save instances of Project without adding a name. What might I be doing wrong?

Try to keep your attributes "nullable", i.e. Allow null = True. Why? Because you usually end up wanting to see the difference between "nothing" and "empty".
As Hans suggested, add a contraint on the class with a expression like this "not self.Name.isNullOrEmpty".

I guess the string is not null but empty "". Strings are tricky that way - the only type that is presented the same as null and as its simplest possible value.
To signal to user that you do not allow a null or empty you can do a constraint on the class or add a validation expression in the ViewModel.

Related

How can i fix bug routes length was called on null when i add element in the Hive Db in Flutter? [duplicate]

I have some code and when I run it produces an error, saying:
NoSuchMethod: the method 'XYZ' was called on null
What does that mean and how do I fix it?
Why do I get this error?
Example
As a real world comparison, what just happened is this conversation:
Hey, how much gas is left in the tank of the car?
What are you talking about, we don't have a car.
That is exactly what is happening in your program. You wanted to call a function like _car.getGasLevel(); but there is no car, the variable _car is null.
Obviously, in your program it might not be a car. It could be a list or a string or anything else really.
Technical explanation
You are trying to use a variable that is null. Either you have explicitly set it to null, or you just never set it at all, the default value is null.
Like any variable, it can be passed into other functions. The place where you get the error might not be the source. You will have to follow the leads from the actual null value to where it originally came from, to find what the problem is and what the solution might be.
null can have different meanings: variables not set to another value will be null, but sometimes null values are used by programmers intentionally to signal that there is no value. Databases have nullable fields, JSON has missing values. Missing information may indeed be the information itself. The variable bool userWantsPizzaForDinner; for example might be used for true when the user said yes, false when the user declined and it might still be null when the user has not yet picked something. That's not a mistake, it's intentionally used and needs to be handled accordingly.
How do I fix it?
Find it
Use the stack trace that came with the error message to find out exactly which line the error was on. Then set a breakpoint on that line. When the program hits the breakpoint, inspect all the values of the variables. One of them is null, find out which one.
Fix it
Once you know which variable it is, find out how it ended up being null. Where did it come from? Was the value never set in the first place? Was the value another variable? How did that variable got it's value. It's like a line of breadcrumbs you can follow until you arrive at a point where you find that some variable was never set, or maybe you arrive at a point where you find that a variable was intentionally set to null. If it was unintentional, just fix it. Set it to the value you want it to have. If it was intentional, then you need to handle it further down in the program. Maybe you need another if to do something special for this case. If in doubt, you can ask the person that intentionally set it to null what they wanted to achieve.
simply the variable/function you are trying to access from the class does not exist
someClass.xyz();
above will give the error
NoSuchMethod: the method 'xyz' was called on null
because the class someClass does not exist
The following will work fine
// SomeClass created
// SomeClass has a function xyz
class SomeClass {
SomeClass();
void xyz() {
print('xyz');
}
}
void main() {
// create an instance of the class
final someClass = SomeClass();
// access the xyz function
someClass.xyz();
}

Error in flutter : The method 'text' was called on null. Receiver: null while localization [duplicate]

I have some code and when I run it produces an error, saying:
NoSuchMethod: the method 'XYZ' was called on null
What does that mean and how do I fix it?
Why do I get this error?
Example
As a real world comparison, what just happened is this conversation:
Hey, how much gas is left in the tank of the car?
What are you talking about, we don't have a car.
That is exactly what is happening in your program. You wanted to call a function like _car.getGasLevel(); but there is no car, the variable _car is null.
Obviously, in your program it might not be a car. It could be a list or a string or anything else really.
Technical explanation
You are trying to use a variable that is null. Either you have explicitly set it to null, or you just never set it at all, the default value is null.
Like any variable, it can be passed into other functions. The place where you get the error might not be the source. You will have to follow the leads from the actual null value to where it originally came from, to find what the problem is and what the solution might be.
null can have different meanings: variables not set to another value will be null, but sometimes null values are used by programmers intentionally to signal that there is no value. Databases have nullable fields, JSON has missing values. Missing information may indeed be the information itself. The variable bool userWantsPizzaForDinner; for example might be used for true when the user said yes, false when the user declined and it might still be null when the user has not yet picked something. That's not a mistake, it's intentionally used and needs to be handled accordingly.
How do I fix it?
Find it
Use the stack trace that came with the error message to find out exactly which line the error was on. Then set a breakpoint on that line. When the program hits the breakpoint, inspect all the values of the variables. One of them is null, find out which one.
Fix it
Once you know which variable it is, find out how it ended up being null. Where did it come from? Was the value never set in the first place? Was the value another variable? How did that variable got it's value. It's like a line of breadcrumbs you can follow until you arrive at a point where you find that some variable was never set, or maybe you arrive at a point where you find that a variable was intentionally set to null. If it was unintentional, just fix it. Set it to the value you want it to have. If it was intentional, then you need to handle it further down in the program. Maybe you need another if to do something special for this case. If in doubt, you can ask the person that intentionally set it to null what they wanted to achieve.
simply the variable/function you are trying to access from the class does not exist
someClass.xyz();
above will give the error
NoSuchMethod: the method 'xyz' was called on null
because the class someClass does not exist
The following will work fine
// SomeClass created
// SomeClass has a function xyz
class SomeClass {
SomeClass();
void xyz() {
print('xyz');
}
}
void main() {
// create an instance of the class
final someClass = SomeClass();
// access the xyz function
someClass.xyz();
}

Selecting list of objects where property of a specific type in entityframework

Currently struggling to filter a list of objects (called Field) where these objects have an inherited property, this property is called FieldReference. This is an abstract class and all Field objects have this property but it can be of different types such as;
DebtorFieldReference
What we're trying to do is query all fields where the Property is of the type DebtorFieldReference and further more we also want to then filter on a value in this DebtorFieldReference object called DebtorId.
We tried the following snippet but EF doesnt allow us to cast, we also tried to query on GetType without success.
var results = FieldProvider.Get(f => f.FieldOwnerTypeId == (byte)Enum.FieldReferenceType.Debtor && ((DebtorFieldReference)f.FieldReference).DebtorId == message.Reference);
I've in the past done this with NHibernate without any problems, please tell me i'm just doing something wrong and EF isn't hugely limited in this way :-(
Thank you for your help.
After some trial and error I actually got it working, not entirely sure why this would work but the Cast would not but here is the line that did it;
var results = FieldProvider.Get(f => (f.FieldReference as DebtorFieldReference).DebtorId == message.Reference);
So in other words, use 'as' and not cast, maybe cast and as behave differently when it concerns null values.

Spring batch: FieldSetMapper should set field to null instead of empty

I am using spring batch to read pipe (| delimited) separated file which have have 7 field. I created a class called MyLineMapper that extends spring's FieldSetMapper. This class maps field values provided in file to my object (XYZ type). Now the problem is that fieldSet object that i get inside class extending FieldSetMapper contain empty value for field that are not present in delimited values.
For example:
Suppose that the delimited file format is as follows: |ID|Country|City|Pin|
Suppose i provide following line in file: |1|India|
As you can see the above line does not contain information for City and Pin. Therefore, I expect FieldSet object should contain Null value for these two fiels (City and Pin) instead of empty string. I don't want empty value as Null will help me to know if that field was actually present in file or not.
How can I achieve this ? Do I need to extend DelimitedLineTokenizer which I am using for tokenizing ? Or this is a simple way to do this ?
Any help will be appreciated.
From FieldSetMapper javadoc
To customize the way that FieldSet values are converted to the desired
type for injecting into the prototype there are several choices. You
can inject PropertyEditor instances directly through the customEditors
property, or you can override the createBinder(Object) and
initBinder(DataBinder) methods, or you can provide a custom FieldSet
implementation.
Depending on type of your target bean conversion is done using default Spring convention. If you need other type of logic write your own.

EnumType.STRING ignored by ebean and Play 2

I have a field definition that is set as an enumeration with EnumType.STRING.
Typically, this works nicely, but on two occasions, it has ignored the EnumType attribute and used the ordinal value for the enumeration.
My declaration looks like this:
#Basic(optional=true) #Enumerated(EnumType.STRING)
public StationFormat stationFormat;
I've tried:
Changing the name of the field
It still creates it as an ordinal
Doing a clean compile
Still uses ordinal value
Adding a second field on the same class
Still uses ordinal value
What the heck? I had this happen before, and at some point it magically resolved itself.
-John
I found a solution to this problem, thought I believe the underlying issue is a bug.
To workaround, add the same enum to a DIFFERENT model class. Does not matter which one, and you can delete it immediately afterwards. It will be added correctly to the new class, as well as the existing class will be amended to use the name() value rather than the ordinal.