Ejemplo n.º 1
0
 public PropertyContext(object target, INakedObjectAssociation property, bool isEdit, PropertyContext parentContext = null)
     : base(target) {
     Property = property;
     IsPropertyEdit = isEdit;
     IsEdit = isEdit;
     ParentContext = parentContext;
 }
 public PropertyContext(IIdHelper idHelper, IObjectFacade target, IAssociationFacade property, bool isEdit, PropertyContext parentContext = null)
     : base(idHelper, target)
 {
     Property       = property;
     IsPropertyEdit = isEdit;
     IsEdit         = isEdit;
     ParentContext  = parentContext;
 }
 public PropertyContext(INakedObject target, IAssociationSpec property, bool isEdit, PropertyContext parentContext = null)
     : base(target)
 {
     Property       = property;
     IsPropertyEdit = isEdit;
     IsEdit         = isEdit;
     ParentContext  = parentContext;
 }
 public PropertyContext(IIdHelper idHelper, PropertyContext otherContext)
     : base(idHelper, otherContext)
 {
     ParentContext = otherContext.ParentContext;
 }
        private static string GetReferenceField(this HtmlHelper html,
                                                PropertyContext propertyContext,
                                                string id,
                                                string tooltip,
                                                IList<ElementDescriptor> childElements,
                                                bool addToThis,
                                                bool readOnly,
                                                bool noFinder) {
            var tag = new TagBuilder("div");
            tag.AddCssClass(IdConstants.ObjectName);

            if (!propertyContext.Property.IsVisible(propertyContext.Target)) {
                var existingValue = propertyContext.GetValue(html.Facade());
                string value = existingValue == null ? String.Empty : Encode(html.Facade().OidTranslator.GetOidTranslation(existingValue));
                tag.InnerHtml += html.Encrypted(id, value).ToString();
                propertyContext.IsPropertyEdit = false;
            } else {
                if (readOnly) {
                    var valueNakedObject = propertyContext.GetValue(html.Facade());
                    string valueId = valueNakedObject == null ? String.Empty : Encode(html.Facade().OidTranslator.GetOidTranslation(valueNakedObject));

                    tag.InnerHtml += html.ObjectIcon(propertyContext.Property.GetValue(propertyContext.Target)) +
                                     html.GetFieldValue(propertyContext) +
                                     html.CustomEncrypted(id, valueId);
                    propertyContext.IsPropertyEdit = false;
                } else if (propertyContext.Property.IsChoicesEnabled != Choices.NotEnabled) {
                    IEnumerable<SelectListItem> items = html.GetItems(id, propertyContext);

                    tag.InnerHtml += html.ObjectIcon(propertyContext.Property.GetValue(propertyContext.Target)) +
                                     html.DropDownList(id, items, new { title = tooltip }) +
                                     html.GetMandatoryIndicator(propertyContext) +
                                     html.ValidationMessage(id);
                } else {
                    var valueNakedObject = html.GetExistingValue(id, propertyContext);
                    var suggestedItem = html.GetSuggestedItem(id, valueNakedObject);
                    string valueId = suggestedItem == null ? String.Empty : Encode(html.Facade().OidTranslator.GetOidTranslation(suggestedItem));

                    if (!propertyContext.Target.IsTransient) {
                        // do not only allow drag and drop onto transients - otherwise  attempt to validate 
                        // may depend on missing fields/data. cf check at top of AjaxControllerImpl:ValidateProperty

                        string url = html.GenerateUrl("ValidateProperty", "Ajax", new RouteValueDictionary(new {
                            id = Encode(html.Facade().OidTranslator.GetOidTranslation(propertyContext.Target)),
                            propertyName = propertyContext.Property.Id
                        }));
                        tag.MergeAttribute("data-validate", url);
                    }
                    //Translates to: Only render finder if the Context is FindMenu enabled AND 
                    //calling code has not overridden it by setting noFinder to true.
                    noFinder = noFinder || !propertyContext.IsFindMenuEnabled();

                    tag.InnerHtml += html.ObjectIcon(suggestedItem) +
                                     html.GetFieldValue(propertyContext, suggestedItem, noFinder) +
                                     html.GetMandatoryIndicator(propertyContext) +
                                     html.ValidationMessage(propertyContext.Property.IsAutoCompleteEnabled ? propertyContext.GetAutoCompleteFieldId() : id) +
                                     html.CustomEncrypted(id, valueId);
                    propertyContext.IsPropertyEdit = false;
                }
            }
            AddInsertedElements(childElements, addToThis, tag);
            return tag.ToString();
        }
 internal static ElementDescriptor ViewObjectField(this HtmlHelper html, PropertyContext propertyContext) {
     return new ElementDescriptor {
         TagType = "div",
         Label = html.GetLabel(propertyContext),
         Value = html.GetViewValue(propertyContext),
         Attributes = new RouteValueDictionary(new {
             id = propertyContext.GetFieldId(),
             @class = propertyContext.GetFieldClass()
         })
     };
 }
Ejemplo n.º 7
0
 public PropertyContext(PropertyContext otherContext) : base(otherContext) {
     ParentContext = otherContext.ParentContext;
 }
        private static string GetViewValue(this HtmlHelper html, PropertyContext propertyContext) {
            string tooltip = propertyContext.Property.Description;
            if (propertyContext.Property.IsCollection && !propertyContext.Property.Specification.IsFileAttachment) {
                return html.GetChildCollection(propertyContext);
            }

            return html.GetViewField(propertyContext, tooltip);
        }
        internal static ElementDescriptor EditObjectField(this HtmlHelper html,
                                                          PropertyContext propertyContext,
                                                          bool noFinder = false,
                                                          IList<ElementDescriptor> childElements = null,
                                                          string idToAddTo = null) {
            string editValue = html.GetEditValue(propertyContext, childElements, propertyContext.Property.Id == idToAddTo, noFinder);

            return new ElementDescriptor {
                TagType = "div",
                Label = html.GetLabel(propertyContext),
                Value = editValue,
                Attributes = new RouteValueDictionary(new {
                    id = propertyContext.GetFieldId(),
                    @class = propertyContext.GetFieldClass()
                })
            };
        }
        private static void AddAjaxDataUrlsToElementSet(this HtmlHelper html, IObjectFacade nakedObject, TagBuilder fieldSet, PropertyContext parent = null) {
            var parameters = new HashSet<string>(nakedObject.Specification.Properties.SelectMany(p => p.GetChoicesParameters()).Select(t => t.Item1));

            // check the names match 

            var properties = nakedObject.Specification.Properties;
            IEnumerable<string> matches = from p in parameters
                                          from pp in properties
                                          where p.ToLower() == pp.Id.ToLower()
                                          select p;

            if (matches.Count() != parameters.Count) {
                string error = String.Format("On choices method in: {0} one or more properties in: '{1}' does not match a property on that class", nakedObject.Specification.FullName, parameters.Aggregate("", (s, t) => s + " " + t));
                throw new ArgumentException(error);
            }

            string parameterNames = parameters.Aggregate("", (s, t) => (s == "" ? "" : s + ",") + new PropertyContext(html.IdHelper(), nakedObject, nakedObject.Specification.Properties.Single(p => p.Id.ToLower() == t.ToLower()), false, parent).GetFieldInputId());

            string url = html.GenerateUrl("GetPropertyChoices", "Ajax", new RouteValueDictionary(new { id = Encode(html.Facade().OidTranslator.GetOidTranslation(nakedObject)) }));
            fieldSet.MergeAttribute("data-choices", url);
            fieldSet.MergeAttribute("data-choices-parameters", parameterNames);
        }
        private static string GetEditValue(this HtmlHelper html,
                                           PropertyContext propertyContext,
                                           IList<ElementDescriptor> childElements,
                                           bool addToThis,
                                           bool noFinder) {
            string tooltip = propertyContext.Property.Description;
            string id = propertyContext.GetFieldInputId();
            if (propertyContext.Property.IsCollection) {
                propertyContext.IsPropertyEdit = false;
                return html.GetChildCollection(propertyContext);
            }
            var consent = propertyContext.Property.IsUsable(propertyContext.Target);
            if (consent.IsVetoed && !propertyContext.Target.IsTransient) {
                propertyContext.IsPropertyEdit = false;
                return html.GetViewField(propertyContext, consent.Reason);
            }

            bool readOnly = consent.IsVetoed && propertyContext.Target.IsTransient;

            // for the moment do not allow file properties to be edited 
            if (propertyContext.Property.Specification.IsFileAttachment) {
                // return html.GetFileProperty(propertyContext, id, tooltip);
                readOnly = true;
            }

            if (propertyContext.Property.Specification.IsParseable) {
                return html.GetTextField(propertyContext, id, tooltip, readOnly);
            }

            if (propertyContext.Property.IsInline) {
                var inlineNakedObject = propertyContext.GetValue(html.Facade());
                TagBuilder elementSet = ElementDescriptor.BuildElementSet(html.EditObjectFields(inlineNakedObject, propertyContext, x => true, null, true));
                html.AddAjaxDataUrlsToElementSet(inlineNakedObject, elementSet, propertyContext);

                return elementSet.ToString();
            }

            return html.GetReferenceField(propertyContext, id, tooltip, childElements, addToThis, readOnly, noFinder);
        }
        private static string GetChildCollection(this HtmlHelper html, PropertyContext propertyContext) {
            string displayType = html.ViewData.ContainsKey(propertyContext.GetFieldId()) ? (string)html.ViewData[propertyContext.GetFieldId()] : String.Empty;
            bool renderEagerly = RenderEagerly(propertyContext.Property);

            var tag = new TagBuilder("div");
            if (displayType == IdConstants.TableDisplayFormat || (String.IsNullOrWhiteSpace(displayType) && renderEagerly)) {
                tag.AddCssClass(IdConstants.CollectionTableName);
                tag.InnerHtml += html.GetCollectionAsTable(propertyContext);
            } else if (displayType == IdConstants.ListDisplayFormat) {
                tag.AddCssClass(IdConstants.CollectionListName);
                tag.InnerHtml += html.GetCollectionAsList(propertyContext);
            } else {
                tag.AddCssClass(IdConstants.CollectionSummaryName);
                tag.InnerHtml += html.GetCollectionAsSummary(propertyContext);
            }

            return tag.ToString();
        }
 private static string GetCollectionTitle(PropertyContext propertyContext, int count) {
     var tag = new TagBuilder("div");
     tag.AddCssClass(IdConstants.ObjectName);
     tag.MergeAttribute("title", "");
     var property = propertyContext.Property;
     var coll = propertyContext.Property.GetValue(propertyContext.Target);
     tag.InnerHtml += property.GetTitle(coll);
     return tag.ToString();
 }
 private static string GetCollectionAsList(this HtmlHelper html, PropertyContext propertyContext) {
     var collectionNakedObject = propertyContext.GetValue(html.Facade());
     bool any = collectionNakedObject.ToEnumerable().Any();
     Func<IObjectFacade, string> linkFunc = item => html.Object(html.ObjectTitle(item).ToString(), IdConstants.ViewAction, item.Object).ToString();
     return (any ? html.GetCollectionDisplayLinks(propertyContext) : GetCollectionTitle(propertyContext, 0)) +
            html.CollectionTable(collectionNakedObject, linkFunc, x => false, null, false, false, true);
 }
 private static string GetCollectionAsSummary(this HtmlHelper html, PropertyContext propertyContext) {
     if (DoNotCount(propertyContext.Property)) {
         return html.GetCollectionDisplayLinks(propertyContext);
     }
     int count = propertyContext.Property.Count(propertyContext.Target);
     return (count > 0 ? html.GetCollectionDisplayLinks(propertyContext) : String.Empty) + GetCollectionTitle(propertyContext, count);
 }
        private static string GetCollectionAsTable(this HtmlHelper html, PropertyContext propertyContext) {
            var collectionNakedObject = propertyContext.GetValue(html.Facade());
            bool any = collectionNakedObject.ToEnumerable().Any();
            Func<IObjectFacade, string> linkFunc = item => html.Object(html.ObjectTitle(item).ToString(), IdConstants.ViewAction, item.Object).ToString();

            Func<IAssociationFacade, bool> filterFunc;
            Func<IAssociationFacade, int> orderFunc;
            bool withTitle;

            GetTableColumnInfo(propertyContext.Property, out filterFunc, out orderFunc, out withTitle);

            return (any ? html.GetCollectionDisplayLinks(propertyContext) : GetCollectionTitle(propertyContext, 0)) +
                   html.CollectionTable(collectionNakedObject, linkFunc, filterFunc, orderFunc, false, false, withTitle);
        }
 private static void AddPasswordControl(this HtmlHelper html, TagBuilder tag, RouteValueDictionary htmlAttributes, PropertyContext context, string id, string value) {
     var length = context.Property.TypicalLength;
     htmlAttributes["size"] = length == 0 ? 20 : length;
     tag.InnerHtml += html.Password(id, value, htmlAttributes) + html.GetMandatoryIndicator(context) + html.ValidationMessage(id);
 }
        private static string GetViewField(this HtmlHelper html, PropertyContext propertyContext, string tooltip, bool addIcon = true, bool inTable = false) {
            var tag = new TagBuilder("div");

            if (propertyContext.Property.IsVisible(propertyContext.Target)) {
                string value = html.GetFieldValue(propertyContext, inTable);
                string cls = propertyContext.Property.Specification.IsParseable ? IdConstants.ValueName : IdConstants.ObjectName;

                if (propertyContext.Property.NumberOfLines > 1) {
                    cls += (" " + IdConstants.MultilineDisplayFormat);
                }

                tag.AddCssClass(cls);
                tag.MergeAttribute("title", tooltip);
                if (!propertyContext.Property.Specification.IsParseable && addIcon) {
                    tag.InnerHtml += html.ObjectIcon(propertyContext.Property.GetValue(propertyContext.Target));
                }
                tag.InnerHtml += value;
            }
            return tag.ToString();
        }
        private static string ZeroValueIfTransientAndNotSet(this HtmlHelper html, PropertyContext propertyContext, string value) {
            if (propertyContext.Target.IsTransient && !String.IsNullOrEmpty(value)) {
                var valueNakedObject = propertyContext.GetValue(html.Facade());

                if (!propertyContext.Property.DefaultTypeIsExplicit(propertyContext.Target) && ShouldClearValue(valueNakedObject.Object)) {
                    value = null;
                }
            }
            return value;
        }
 private static bool IsMandatory(this HtmlHelper html, PropertyContext propertyContext) {
     return (propertyContext.Property.IsMandatory && propertyContext.Property.IsUsable(propertyContext.Target).IsAllowed);
 }
        private static string GetHiddenValue(this HtmlHelper html, PropertyContext propertyContext, string id, bool invariant) {
            var tag = new TagBuilder("div");
            string value;

            if (propertyContext.Property.Specification.IsParseable) {
                tag.AddCssClass(IdConstants.ValueName);
                value = invariant ? html.GetInvariantValue(propertyContext) : html.GetRawValue(propertyContext);
            } else {
                tag.AddCssClass(IdConstants.ObjectName);
                var existingValue = propertyContext.GetValue(html.Facade());
                value = existingValue == null ? String.Empty : Encode(html.Facade().OidTranslator.GetOidTranslation(existingValue));
            }
            tag.InnerHtml += html.Encrypted(id, value).ToString();
            return tag.ToString();
        }
        private static string GetTextField(this HtmlHelper html, PropertyContext propertyContext, string id, string tooltip, bool readOnly) {
            var tag = new TagBuilder("div");
            tag.AddCssClass(IdConstants.ValueName);

            var htmlAttributes = new RouteValueDictionary(new { title = tooltip });

            html.AddClientValidationAttributes(propertyContext, htmlAttributes);

            if (!propertyContext.Property.IsVisible(propertyContext.Target)) {
                tag.InnerHtml += html.Encrypted(id, html.GetRawValue(propertyContext)).ToString();
                propertyContext.IsPropertyEdit = false;
            } else if (propertyContext.Property.Specification.IsBoolean && !readOnly) {
                var state = propertyContext.Property.GetValue(propertyContext.Target).GetDomainObject<bool?>();

                if (propertyContext.Property.IsNullable) {
                    html.AddTriState(tag, htmlAttributes, id, state);
                } else {
                    html.AddCheckBox(tag, htmlAttributes, id, state);
                }
            } else if (propertyContext.Property.Specification.IsDateTime && !readOnly) {
                html.AddDateTimeControl(tag, htmlAttributes, propertyContext, id, html.GetPropertyValue(propertyContext));
            } else if (propertyContext.Property.IsPassword && !readOnly) {
                html.AddPasswordControl(tag, htmlAttributes, propertyContext, id, html.GetPropertyValue(propertyContext));
            } else if (propertyContext.Property.IsChoicesEnabled != Choices.NotEnabled && !readOnly) {
                html.AddDropDownControl(tag, htmlAttributes, propertyContext, id);
            } else if (propertyContext.Property.IsAutoCompleteEnabled && !readOnly) {
                html.AddAutoCompleteControl(tag, htmlAttributes, propertyContext, propertyContext.Property.GetValue(propertyContext.Target));
            } else {
                string rawValue = html.GetRawValue(propertyContext);
                if (readOnly) {
                    tag.InnerHtml += html.GetFieldValue(propertyContext) + html.CustomEncrypted(id, rawValue);
                    propertyContext.IsPropertyEdit = false;
                } else {
                    html.AddTextControl(tag, htmlAttributes, propertyContext, id, html.ZeroValueIfTransientAndNotSet(propertyContext, rawValue));
                }
            }

            return tag.ToString();
        }
 internal static MvcHtmlString ObjectPropertyEdit(this HtmlHelper html, PropertyContext propertyContext) {
     return MvcHtmlString.Create(html.EditObjectField(propertyContext).BuildElement());
 }
        private static void AddTextControl(this HtmlHelper html, TagBuilder tag, RouteValueDictionary htmlAttributes, PropertyContext context, string id, string value) {
            var typicalLength = context.Property.TypicalLength;
            var maxLength = context.Property.MaxLength.GetValueOrDefault(0);
            int numberOfLines = context.Property.NumberOfLines;
            int width = context.Property.Width;

            width = width == 0 ? (typicalLength == 0 ? 20 : typicalLength) / numberOfLines : width;

            string textBox = html.GetTextControl(id, numberOfLines, width, maxLength, value, htmlAttributes);
            tag.InnerHtml += textBox + html.GetMandatoryIndicator(context) + html.ValidationMessage(id);
        }
        internal static IEnumerable<ElementDescriptor> EditObjectFields(this HtmlHelper html,
                                                                        IObjectFacade nakedObject,
                                                                        PropertyContext parentContext,
                                                                        Func<IAssociationFacade, bool> filter,
                                                                        Func<IAssociationFacade, int> order,
                                                                        bool noFinder = false,
                                                                        IList<ElementDescriptor> childElements = null,
                                                                        string idToAddTo = null) {
            var query = nakedObject.Specification.Properties.Where(p => p.IsVisible(nakedObject)).Where(filter);

            if (order != null) {
                query = query.OrderBy(order);
            }

            var visibleFields = query.ToList();

            IEnumerable<ElementDescriptor> visibleElements = visibleFields.Select(property => html.EditObjectField(new PropertyContext(html.IdHelper(), nakedObject, property, true, parentContext), noFinder, childElements, idToAddTo));

            if (nakedObject.IsTransient) {
                IEnumerable<ElementDescriptor> hiddenElements = nakedObject.Specification.Properties.Where(p => !p.IsCollection && !p.IsVisible(nakedObject)).
                    Select(property => new ElementDescriptor {
                        TagType = "div",
                        Value = html.GetEditValue(new PropertyContext(html.IdHelper(), nakedObject, property, true, parentContext), childElements, property.Id == idToAddTo, noFinder)
                    });

                visibleElements = visibleElements.Union(hiddenElements);

                IEnumerable<ElementDescriptor> collectionElements = nakedObject.Specification.Properties.Where(p => p.IsCollection).
                    SelectMany(p => p.Items(html, nakedObject)).
                    Select(t => new ElementDescriptor {
                        TagType = "div",
                        Value = html.GetCollectionItem(t.Item2, html.IdHelper().GetCollectionItemId((nakedObject), (t.Item1)))
                    });

                visibleElements = visibleElements.Union(collectionElements);
            }

            // add filtered fields as hidden to preserve their values 

            var filteredFields = nakedObject.Specification.Properties.Where(p => !p.IsCollection && p.IsVisible(nakedObject)).Except(visibleFields);
            IEnumerable<ElementDescriptor> filteredElements = filteredFields.Select(property => new PropertyContext(html.IdHelper(), nakedObject, property, false, parentContext)).Select(pc => new ElementDescriptor {
                TagType = "div",
                Value = html.GetHiddenValue(pc, pc.GetFieldInputId(), false)
            });
            IEnumerable<ElementDescriptor> elements = visibleElements.Union(filteredElements);

            if (!nakedObject.IsTransient) {
                // if change existing object add concurrency check fields as hidden  

                IEnumerable<ElementDescriptor> concurrencyElements = html.GetConcurrencyElements(nakedObject, x => new PropertyContext(html.IdHelper(), nakedObject, x, false, parentContext).GetConcurrencyFieldInputId());
                elements = elements.Union(concurrencyElements);
            }

            return elements;
        }
 private static void AddAutoCompleteControl(this HtmlHelper html, TagBuilder tag, RouteValueDictionary htmlAttributes, PropertyContext context, IObjectFacade valueNakedObject) {
     tag.InnerHtml += html.GetAutoCompleteTextBox(context, htmlAttributes, valueNakedObject) + html.GetMandatoryIndicator(context) + html.ValidationMessage(context.GetAutoCompleteFieldId());
 }
        internal static IEnumerable<ElementDescriptor> ViewObjectFields(this HtmlHelper html, IObjectFacade nakedObject, PropertyContext parentContext, Func<IAssociationFacade, bool> filter, Func<IAssociationFacade, int> order, out bool anyEditableFields) {
            var query = nakedObject.Specification.Properties.Where(p => p.IsVisible(nakedObject)).Where(filter);

            if (order != null) {
                query = query.OrderBy(order);
            }

            var visibleFields = query.ToList();
            anyEditableFields = visibleFields.Any(p => p.IsUsable(nakedObject).IsAllowed);
            return visibleFields.Select(property => html.ViewObjectField(new PropertyContext(html.IdHelper(), nakedObject, property, false, parentContext)));
        }
Ejemplo n.º 28
0
 public PropertyContext(PropertyContext otherContext) : base(otherContext)
 {
     ParentContext = otherContext.ParentContext;
 }
 private static IEnumerable<SelectListItem> GetChoicesSet(this HtmlHelper html,
                                                          PropertyContext propertyContext,
                                                          IObjectFacade existingNakedObject,
                                                          IDictionary<string, IObjectFacade> values) {
     var nakedObjects = propertyContext.Property.GetChoices(propertyContext.Target, values.ToDictionary(kvp => kvp.Key, kvp => kvp.Value == null ? null : kvp.Value.Object)).ToList();
     return html.GetChoicesSet(nakedObjects, existingNakedObject);
 }
        private static IEnumerable<SelectListItem> GetItems(this HtmlHelper html, string id, PropertyContext propertyContext) {
            IObjectFacade existingValue;

            if (propertyContext.Target.IsTransient && !propertyContext.Property.DefaultTypeIsExplicit(propertyContext.Target)) {
                // ignore implicit defaults on transients
                existingValue = null;
            } else {
                existingValue = html.GetExistingValue(id, propertyContext);
            }

            var values = new Dictionary<string, IObjectFacade>();
            var choicesParameters = propertyContext.Property.GetChoicesParameters();

            if (choicesParameters.Any()) {
                values = propertyContext.Target.Specification.Properties.
                    Where(p => choicesParameters.Select(pnt => pnt.Item1).Contains(p.Id.ToLower())).
                    ToDictionary(p => p.Id.ToLower(),
                        p => html.GetExistingValue(html.IdHelper().GetFieldInputId(propertyContext.Target, p),
                            new PropertyContext(html.IdHelper(), propertyContext) {
                                Property = p
                            }));
            }

            return html.GetChoicesSet(propertyContext, existingValue, values);
        }
 private static string GetPropertyValue(this HtmlHelper html, PropertyContext propertyContext) {
     var valueNakedObject = propertyContext.GetValue(html.Facade());
     string value = propertyContext.Property.GetMaskedValue(valueNakedObject);
     value = html.ZeroValueIfTransientAndNotSet(propertyContext, value);
     return value;
 }
 private static string GetLabel(this HtmlHelper html, PropertyContext propertyContext) {
     bool isAutoComplete = propertyContext.IsEdit && propertyContext.Property.IsAutoCompleteEnabled;
     Func<string> propId = isAutoComplete ? (Func<string>)propertyContext.GetAutoCompleteFieldId : propertyContext.GetFieldInputId;
     return GetLabelTag(propertyContext.IsPropertyEdit || isAutoComplete, propertyContext.Property.Name, propId);
 }
 private static void AddDateTimeControl(this HtmlHelper html, TagBuilder tag, RouteValueDictionary htmlAttributes, PropertyContext context, string id, string value) {
     var typicalLengthFacet = context.Property.TypicalLength;
     htmlAttributes["size"] = typicalLengthFacet == 0 ? 20 : typicalLengthFacet;
     htmlAttributes["class"] = "datetime";
     tag.InnerHtml += html.TextBox(id, value, htmlAttributes) + html.GetMandatoryIndicator(context) + html.ValidationMessage(id);
 }
        private static IObjectFacade GetExistingValue(this HtmlHelper html, string id, PropertyContext propertyContext) {
            ModelState modelState;
            string rawExistingValue = html.ViewData.ModelState.TryGetValue(id, out modelState) ? (string)modelState.Value.RawValue : null;

            IObjectFacade existingValue;
            if (String.IsNullOrEmpty(rawExistingValue)) {
                existingValue = propertyContext.GetValue(html.Facade());
            } else {
                existingValue = propertyContext.Property.Specification.IsParseable ? html.Facade().GetObject(propertyContext.Property.Specification, rawExistingValue) :
                    html.Facade().GetObject(html.Facade().OidTranslator.GetOidTranslation((string)modelState.Value.RawValue)).Target;
            }
            return existingValue;
        }