I am using some attribute based validation.
I wish to condition the submit command based on the boolean result of TryValidateObject. I need this to return without adding any validation errors to the ValidationErrors Collection. Otherwise a newly added record will immediately show errors - even before the users has keyed any input.
This happens because the CanExecute method of the submit command executes immediately.
When I have finished with the current record (or on exit from the current field) I will call ValidateObject which should produce errors.
The problem seems to be that the ValidationAttribute class has no way to determine if its IsValid method is being invoked by TryValidateObject or ValidateObject. n.b. The IsValid method is where I add ValidationErrors to the ValidationResults collection.
How can I solve this.
Related
In adf, I have a table in which the autosubmit is set to true for a column. When we change this value it is going through its life cycle and the value is getting update but the entity validations for that row is getting skipped when toggling to the other rows, but when we try to commit it to the DB it is getting validated since the transaction became dirty. Is there any feature which helps it to do the entity validation or anything wrong with my concept.
P.S: It is working fine when autosubmit = "false" i.e entity validation is trigger while toggling between the rows before committing it to the DB.
I believe that usually autoSubmit validation would fire on a navigationevent. It is hard to know exactly what is wrong without seeing your code, but some things that might resolve your problem include:
Ensure the validation is for the attribute being submitted and not for the whole row
Ensure you have not set skipValidation="true" or altered the phase in another way (ie pageDef)
Ensure if you have overridden the default rowNavigationListener that is still triggering validation.
Ensure there is no ppr removing your the error message from the validation on row navigation and making it appear as if validation that actually did occur, did not.
Try adding BlockRowNavigationOnError="always" to your table and see if it still lets you change rows.
I am using Jdeveloper 11.1.2.0.0
I have a jsf page in which there is a input text field and a command button.
The command button`s work is to just commit.
But i have two setPropertyListener on the command button that sets the value of two mandatory attributes of that VO.
So which will be fired first?
Action or setPropertyListener.
ActionListener fires before Action. SetProperty fires before ActionListener.
Easy to test. Write a simple Java Backing Bean and print a value that is changed by the SetProperty Listener. Then Print in ActionListener and Action and see what the value is and the order of the print statements.
This post may help. And this. And this.
Order of calls made: SetPropertyListener,ActionListener,Action
When I pass {"silent":true} while setting an attribute in a Backbone model, why doesn't that just suppress the change:attribute event? What is the advantage of firing that event the next time an attribute is changed?
Update
Backbone 0.9.10 changed the behavior of passing { "silent": true }. From the changelog:
Passing {silent:true} on change will no longer delay individual
"change:attr" events, instead they are silenced entirely.
Browse the changelog here
This has confused me for some time as well.
The reason is that {silent:true} does not mean "Do everything as normal, but just don't trigger the event".
From various comments and answers by #jashkenas, what it seems to mean is "simply change the attribute value (and add it to the 'changedAttributes' hash), but defer all other "change-related" activities until later".
'silent' doesn't prevent the change event for that/those properties, it simply queues up the 'announcement' until the next change event is triggered.
So, its probably better named something like defer.
Relevant information:
https://github.com/documentcloud/backbone/pull/850
the point of a "silent" change is that it isn't considered a change from the models point of view. Later, when the change actually occurs, you get the full difference all at once.
https://github.com/documentcloud/backbone/issues/870
Because the point of silent changes is that you're allowed to twiddle with the internal state of your model, temporarily, without actually making a change. Later, when the attribute actually changes, the validation runs and events are emitted. It wouldn't make sense to emit an error event when making a silent change.
Update 4/7/2013
Note: I have not tested this to confirm behavior, this is just based on my reading of the release notes...
As of Backbone 0.9.10, the behavior described above has changed. In that version (and newer), silent:true suppresses the change:attr events entirely - not just delays them.
http://backbonejs.org/#changelog
In backbone 0.9.2 the set function runs validation before any changes are updated.
// Run validation.
if (!this._validate(attrs, options)) return false;
In case of {silent: true} option is passed, the validation code will not be executed.
if (options.silent || !this.validate) return true;
That means, model.set({value: 100}, {silent: true}); is able to set "invalid" value into model, so attributes are updated, but change event's are not firing.
It is useful, then you want to update some field and prevent whole mode validation, so if model is not yet completed, the change still propagated to attributes. But you usually you also want the view to show the change, so you have to manually call model.change() or model.trigger('change:value', model, value).
I have couple of objects(1 custom object called appointment and event object) which i am trying to syncronize. So i have 1 trigger each on each object which searches and updates the records. The issue is, these triggers will keep running recursively as everytime an appointmet is updated the event is also updated and the triggers keep firing and ofcourse salesforce does not accept it.
Any idea how to overcome this?
Thanks
Easiest way is to have an apex class containing a static boolean variable initialised to false. Then in each of your triggers you would check the state of this variable:
trigger MyTrigger on MyObject (after update)
{
if(CStaticTracker.bHasTriggerFired == false)
{
CStaticTracker.bHasTriggerFired = true;
// do your work and update the other object here
// shouldn't need this but let's play safe!
CStaticTracker.bHasTriggerFired = false;
}
}
The upshot being, of course, that when one of the triggers runs it'll set this variable to true, and prevent the recursive trigger from executing whatever logic is contained within the if statement. Of course this can still cause some cascading, but it will stop as soon as you don't call another update in one of the triggers.
Good luck!
Caveat: I'm working with a backend that I don't have full control over, so I'm wrestling with a few considerations within Backbone that might be better addressed elsewhere...unfortunately, I have no choice but to handle them here!
So, my problem is that I'd really like to validate user input from a form (when I set values with it on Backbone models), but the models I receive from the API on newly created objects (via posts that ONLY accept a name, and ONLY return a name and object id) will fail my validation checks.
As example, when a new object is created in the database, two key fields are populated as empty strings (and so when Backbone hits the API and populates the models, it populates those keys with empty strings). When the user saves these objects back, post-edit, I'd like to force them to enter values for these two keys -- which is very easy, given Backbone's built in validation method.
The problem, of course, is that the validation is firing on both fetch->set (unwanted behavior) and set->save (desired behavior) -- and so newly created models won't load at all...Backbone collects them, validation fails, and errors fire.
So, my question is: is there a "Backbone-y" way to only validate the models on set->save, not on fetch->set? Could I use a specific trigger to work around this?
Any ideas would be greatly appreciated.
Backbone.Model.set won't perform validation if you pass in { silent: true }, and fetch will pass any options through to set, so you could either override fetch or write your own fetchSilent method that passes that in an options object.
However, you might run into a slight gotcha with Backbone.Collection.fetch, because when it receives attributes from the server, it doesn't create the new models with set. Instead, it creates a new model with model = new this.model(attrs, {collection: this}); and then performs validation if there's a validate method on the object.
This is a little annoying. You can get around it by defining a parse method on your collection (if you're using one) that creates a model silently (using {silent: true}), because when Backbone.Collection.add receives a fully formed Backbone model, it won't run the validation. (see the _add and _prepareModel methods in the annotated source).
It's a little annoying that the collection works that way, but (for now at least) it is what it is.
Instead of overriding fetch you can do another thing:
When you validate your model, check for model.silent and only validate if that doesn't exist.
So you do the following when you want to fetch a model:
var test = new MyModel({ id: '123', silent: true });
// in your Model validate function
validate: function(attrs) {
if (!attrs.silent) {
// validate logic here
}
}
Then you can fetch the model. After you get your model you can unset silent, for future validation.