Habanero.Faces.Base.CheckBoxMapper.ApplyChangesToBusinessObject C# (CSharp) Method

ApplyChangesToBusinessObject() public method

The event handler that is called to update the property on the Business Object when the user has checked or unchecked the CheckBox.
public ApplyChangesToBusinessObject ( ) : void
return void
        public override void ApplyChangesToBusinessObject()
        {
            if (!IsEditable) return;

            bool newValue = _checkBox.Checked;
            bool valueChanged = false;
            if (GetPropertyValue() == null)
            {
                valueChanged = true;
            }
            else
            {
                bool oldValue = Convert.ToBoolean(GetPropertyValue());
                if (newValue != oldValue)
                {
                    valueChanged = true;
                }
            }
            if (valueChanged)
            {
                SetPropertyValue(newValue);
            }
        }

Usage Example

        /// <summary>
        /// Adds click event handler
        /// </summary>
        /// <param name="mapper">The checkbox mapper</param>
        public void AddClickEventHandler(CheckBoxMapper mapper)
        {
            var checkBox = mapper.GetControl() as CheckBox;
            if (checkBox == null) return;

            checkBox.CheckedChanged += delegate
            {
                try
                {
                    mapper.ApplyChangesToBusinessObject();
                    mapper.UpdateControlValueFromBusinessObject();
                }
                catch (Exception ex)
                {
                    GlobalRegistry.UIExceptionNotifier.Notify(ex, "", "Error ");
                }
            };
        }