when i try to get an object in the bootstrap via User.get(1) or User.findById(1) I get always null returned. I saved the object before with new User(...).save(flush: true) and the user is already in User.list()...
who knows the reason/mistake?
thx
The domain is probably not being saved due validation errors.
replace your
user.save(flush:true)
for
if (user.validate()) {
user.save(flush:true)
} else {
user.errors.allErrors.each { println it }
}
It will print all validation errors in your console.
Related
I am using ember-cli:2.5.0 and ember-validations:v2.0.0-alpha.5
In my ember-component i have a validation which is running automatically for each change in a attribute but i want to run this validation only if i call "validate()" method in technical term call validation lazily.
Please find the below code samples,
import Ember from 'ember';
import EmberValidations, { validator } from 'ember-validations';
export default Ember.Component.extend(EmberValidations, {
didReceiveAttrs() {
this.set('newBook', this._bookModel().create());
},
_bookModel(data = {}) {
return Ember.Object.extend(EmberValidations, {
bookVersion: null,
isEditable: false,
validationActive: false,
validations: {
bookVersion: {
inline: validator(function() {
if(this.validationActive){ //Here this.validationActive always return undefined
var version = this.model.get('bookVersion') || "",
message = [];
if (Ember.isEmpty(bookVersion)) {
message.push("Book Version is mandatory!!!");
}
if (message.length > 0) {
return message.join(',');
}
}
})
}
}
}, data);
}
});
actions: {
this.get('newBook').set("validationActive",true);
this.get('newBook').validate().then(() => {
//Do the action
}
}
I want the above validation to run only calling "this.get('newBook').validate()". I am entirely new to ember so down-voter please put your comments before down-voting for others kindly let me know for any more code samples.
Your help should be appreciable.
The addon you are using for validations ("ember-validations") is a very popular one and its documentation is pretty well when compared to others. If you look at the documentation there is a part named "Conditional Validators" in documentation. You can use a boolean property to control when the validation is to be performed.
You can see an illustration of what I mean in the following twiddle. I have created a simple validation within the application controller for user's name. The name field must have a length of at least 5 and the validation is to be performed only if the condition validationActive is true. Initially; the condition is false; which means validator did not work and isValid property of Controller (which is inherited from EmberValidations Mixin) is true. If you toggle the property with the button provided; the validation will run (since the condition is now set to true; hence validation is triggered) and isValid will return to false. If you change the value; the validation result will change appropriately with respect to the value of user's name. If you toggle the condition once again to set it to false; then isValid will become true no matter what the valie of user's name is.
I hope this gives you an insight about how to control when your validations should work.
Here is what you should do after your edit: The field is undefined because you are trying to reach component's own validationActive field within inline validator. Please get validationActive as follows this.model.get('validationActive') and give a try. It should work.
Sorry if this is the wrong place to ask, but I'm writing this validation rule in Oracle Sales Cloud 11 on the account object (field : Address Line 1), and it always returns false even if true, I don't get it. I've tried several formulations, but the issue remains, thanks a lot for your help.
if (PrimaryAddressLine1 == null) {
return false
}
else {
return true
}
Instead of putting the validation at object level, can you place the required/mandatory requirement by configuring in Manage Address Formats and handle it there. Making Address Line 1 required at this Level will make it required across objects where OOTB Address Section is used.
You can try the following code:
if (!PrimaryAddressLine1) {
return false } else {
return true }
I have got a domain class with some custom validators like the following:
class Domain {
String attribute1
OtherDomain attribute2
static constraints = {
attribute2 nullable: true, validator: {OtherDomain od, Domain d ->
if (od) {
log.debug "entering validation"
// certain validation here
}
}
}
For updating I have got a simple action in the corresponding DomainController:
#Transactional
def update(Domain domainInstance) {
log.debug "entering update()"
// rest of update
}
I'm wondering why in my debuglog I get the debug messages in the following order:
entering validation
entering update()
The problem is that the validation fails at this point (StackOverflowError). I know the reason for this error and I know what to do to circumvent this error (doing so within update action). However, I don't know why there is a validation before the programme even gets into the update() action. And I don't know how to prevent a validation at this point.
Do you have any suggestions?
The reason you see the "entering validation" message before "entering update()" is because you have declared a command object of type Domain. This means that Grails will bind any request parameters to domainInstance and then call validate() on it, before the action is executed. This allows you to write code like this:
#Transactional
def update(Domain domainInstance) {
// at this point request params have been bound and validate() has
// been executed, so any validation errors will be available in
// domainInstance.errors
if (domainInstance.hasErrors() {
// do something
}
log.debug "entering update()"
}
I am not sure and facing strange nullpointer issue as below. could someone please help me on this in the below code
if ((COUNTRY_CODE.equalsIgnoreCase(Country.TEST.name())) && (strCellId.matches("[0-9]*")))
is throwing nullpointer in the log file(as per line number). The only offending code i can see is strCellId.matches("[0-9]*") if strCellId is null
however, StringUtils.isNotEmpty(strCellId) is called already before we enter to if condition. please see the condition
public static boolean validateCellId(String strCellId)
{
if (StringUtils.isNotEmpty(strCellId)) {
//here the nullpointer is coming
if ((COUNTRY_CODE.equalsIgnoreCase(Country.TEST.name())) && (strCellId.matches("[0-9]*"))) {
return true;
}
}
return false;
}
Its My Bad .
#zsxwing you are right. My country was not initialized, i should have check this, i just overlooked it with confidence.Thanks
I have a simple ExtJs (3.4) Grid with a Writer. When the user makes some changes the store is saved to the server as follows:
store.on('save', afterSave(resp));
All is fine. However, I want to get a response as to wheather the record has been saved successfully, failed or an update conflict happed. How to best do this?
Are you using Ext.data.proxy.Ajax to load your stores? If so, you can use the reader property to evaluate and handle the server responses.
Another option would be to make AJAX called directly and handle the responses from there as well
I used exception listener to parse the data as suggested here. But, is this the right way to do this.
Ext.data.DataProxy.addListener('exception', function(proxy, type, action,
options, res) {
if (type == 'response') {
var success = Ext.util.JSON.decode(res.responseText).success;
if (success) {
console.log('UPDATE OK');
} else {
console.log('UPDATE FAILED');
}
}
});