EpiServer PendingPublish is true in PublishedPage event - episerver

In EpiServer 6, I need to re-index a page whenever it's published. Inside the PublishedPage event handler, I'm checking whether the page is published or not using:
e.Page.CheckPublishedStatus(PagePublishedStatus.PublishedIgnoreDates)
This method always returns false. The Status property for the page is Published but PendingPublish property is true and I'm assuming that's the reason why CheckPublishedStatus returns false.
When is the PendingPublish property set to false after a page is published? Is there another event handler I can use for my indexing purposes?

Maybe I'm misunderstanding what you're trying to do, but if the PublishedPage event fires the event argument will always be a published page.
So, it seems to me the status check is redundant?

Related

HasChanged Not Working in Backbone 1.1.2

CodePen: http://codepen.io/opnsrce/pen/hclaH
Expected behavior: You should only be able to highlight one item at a time.
Current Behavior: You can highlight multiple items
Cause: HasChanged returns true when checked by the controller during the change event.
When I run this code with Backbone 0.9.2 it works. When I use 1.1.2 it doesn't.
Did something fundamentally change in the way hasChanged works between those two versions?
I believe this is the desired functionality. A model's changed attributes change each time the model itself is set. So until you set a model multiple times it will hold onto its changes. The code you've set up here would work if that hash of changes cleared out when a different model was selected. What is actually happening is that as soon as you set a model to isSelected it will always have isSelected == true and hasChanged('isSelected'), so it will never pass the condition to set isSelected to false.
One way to accomplish what you're looking for is to change your collection method to this:
onSelectedChanged: function(modelActive) {
if(modelActive.get('isSelected') === true){
this.each(function(model) {
if (model != modelActive) {
model.set({isSelected: false});
}
});
}
}
Note that I took out hasChanged since that was simply confirming that a model had changed at some previous point. Instead I compare the actively selected model with the ones being iterated. We don't want to touch the active one. I also check to see if this method was triggered via the setting of isSelected to true because if we don't do that, every setting of the iterated models to false will trigger this method and cause problems.
The only limitation of this is that you can't select the same item to toggle it off.

Trigger backbone.js change when value doesn't change

It's a known feature of backbone.js that when you set data that hasn't changed it won't fire the change event, nor will it go through validations. I however need the change event to fire as I'm storing a JSON response from an AJAX call which stores results of backend validation. If the user keeps submitting the form while leaving the same field empty, the backend validation will return the same JSON result and when I save it to the model it won't trigger the change event.
A few things I've tried within the AJAX success callback where I set the data into the model:
Attempted Solution #1
t.model.unset('fieldErrors',{silent: true});
t.model.set({fieldErrors: JSONResponse});
Attempted Solution #2
t.model.set({fieldErrors: null},{silent: true});
t.model.set({fieldErrors: JSONResponse});
Neither of these results in the change event firing a second time when the call is made and the user has the same JSONResponse.
Manually trigger the change event:
t.model.trigger('change', t.model);
or
t.model.trigger('change:fieldErrors', t.model, newFieldErrorsValue);
this.model.set({fieldErrors: JSONResponse}, {silent:true});
this.model.trigger('change:fieldErrors');
see this conversation:
Can I force an update to a model's attribute to register as a change even if it isn't?

icefaces htmlselectbooleancheckbox uncheck not working

I am using icefaces 1.8.2 and i have a HtmlBooleanCheckbox on my page that I need to uncheck when certain circumstances are met.
the checkbox on the page is like this
<ice:selectBooleanCheckbox id="accepttermscheckbox"
binding="#{managedBean.termsAgreement}"
validator="#{managedBean.validateAgreement}">
</ice:selectBooleanCheckbox>
and the binded object is a property of the managed bean with proper getter and setter
private HtmlSelectBooleanCheckbox termsAgreement;
i can check the checkbox in code, validator works fine and all the stuff i do with it are ok too but I just cant find a way to uncheck it on the server side.
I tried:
termsAgreement.setValue(Boolean.FALSE)
termsAgreement.setValue(null)
termsAgreement.setSelected(false)
but nothing works. Even if I debug it it shows value = null but when the page renders it still appears checked.
Once I check it I just cant get it unchecked unless I click it manually on the page.
funny thing is that
termsAgreement.setValue(Boolean.TRUE)
works fine.
Anyone any tips how I can uncheck it server side on the binded object?
Thank you in advance for help.
You are facing a common issue faced by ICEfaces/JSF developers.
First of all, you need to understand how JSF lifecycle works.
Following is a good article to read.
http://www.ibm.com/developerworks/library/j-jsf2/
For your case, bind a value to <ice:selectBooleanCheckbox>.
For example value="#{managedBean.termsAgreed}".
<ice:selectBooleanCheckbox id="accepttermscheckbox"
binding="#{managedBean.termsAgreement}"
validator="#{managedBean.validateAgreement}"
value="#{managedBean.termsAgreed}">
</ice:selectBooleanCheckbox>
Do not try to change the value from the component. Always change value from the value binding. In this example, you must change the value termsAgreed.
If your action/actionListener is not immediate, i.e `immediate="false", which is the default value, then changing the value in server-side will check/uncheck checkbox component.
If you are using immediate="true", then you must call resetValue() method in your component, HtmlSelectBooleanCheckbox:
termsAgreement.resetValue();
Ideally, you shouldn't call setValue() methods in components. You will understand it when you understand the JSF lifecycle.
Hope this will help!

backbone model with an array/object property: infinite 'change' event triggered after sync()?

My backbone.js model has an array property. I bound the change event to save().
After sync() (triggered by save(), my app server returns an identical JSON, but backbone thinks the array has been changed (due to a different reference to the array I guess?), and trigger changes again. Then an infinite loop occurs.
save() -> sync() -> triggered `change` -> save()...
What shall I do?
Idea: I can bind the change event to a function that checks if the changed attributes are of type object/array, and do a deep comparison and call save only if the array/object really changed. If true then save()?
Thanks!
Try the Edge version of Backbone (master branch) this behavior changed after 0.9.9 - see https://github.com/documentcloud/backbone/pull/2004
Backbone has a special option on many methods to prevent just this sort of issue: silent:true. If you pass that option to your save method, the resulting sync won't trigger a change event.
So, if you want to set your change event handler to save silently, something like:
changeHandler: function() {
this.save({silent:true});
}
should do the trick.

How do you "preview" user actions like resize or editing in GoDiagrams?

The GoDiagram object model has a GoDocument.
GoViews have a reference to a GoDocument.
If the user does any modification on the diagramming surface, a GoDocument.Changed event is raised with the relevant information in the event arguments.
I would like to be notified when some user-actions happen, so that I can confer with my Controller (disallow/cancel it if need be) and then issue view-update orders from there that actually modify the Northwoods GoDiagram third party component.
The Changed event is a notification that something just happened (past tense) - Doing all of the above in the event handler results in a .... (wait for it)... StackOverflowException. (GoDocument.Changed handler > Updates GoDocument > Firing new Changed events.. )
So question, how do I get a BeforeEditing or BeforeResizing kind of notification model in GoDiagrams? Has anyone who's been there lived to tell a tale?
JFYI...
The component-vendor recommendation is to subclass and override appropriate methods for this. Override the bool CanXXX() method, raise a cancelable custom event. If the subscriber returns false, bail out (return false to abort the user action) of CanXXX.
No built-in mechanism for this in GoDiagrams.
For example, you could define a
CustomView.ObjectResizing cancelable
event. In your override of
GoToolResizing.CanStart, you can raise
that event. If the
CancelEventArgs.Cancel property
becomes true, you would have
CanStart() return false.
Source http://www.nwoods.com/forum/forum_posts.asp?TID=2745
The event arguments (GoChangedEventArgs) for the change event has a property IsBeforeChanging which indicates whether the change event was raised from the "RaiseChanging" method (true), or the RaiseChanged (false). That should tell you whether the change has occurred yet, but I know of no way to cancel it.
The best I can suggest is instead of checking if the change is allowed and performing it, check if the change is not allowed, and if it isn't call the "Undo" method on the arguments in the change event. So essentially:
OnChanged(GoChangedEventArgs e)
{
if(NotAllowed)
{
e.Undo();
}
}

Resources