mikeedwards83 / glass.mapper Goto Github PK
View Code? Open in Web Editor NEWVersion 5 of the Glass mapping framework, the best ORM for Sitecore.
License: Apache License 2.0
Version 5 of the Glass mapping framework, the best ORM for Sitecore.
License: Apache License 2.0
I'm seeing that the BeginRenderLink() is adding an additional attribute to the A tags. It places parameters='System.Collections.Specialized.NameValueCollection'. Doesn't break the page but would be nice to track down the issue and remove from final HTML markup.
Code:
<% using (BeginRenderLink(contentItem, x => x.Link, new Glass.Mapper.Sc.RenderField.LinkParameters { Class="moreLink", Title="Multifamily" }, isEditable: true)) {%>
<%= Editable(contentItem, c=>c.Link_Text) %>
<% } %>
Output:
<a href='http://www.sample.com/' target='_blank' title='Multifamily' class='moreLink' text='' parameters='System.Collections.Specialized.NameValueCollection'>
Multifamily
</a>
When the .Item property is set to null on the rendering parameter in the GetRendererMethod(Rendering rendering, GetRendererArgs args) method of any of the three processors below, an exception occurs that results in pages not being rendered.
Glass.Mapper.Sc.Razor.Pipelines.GetRenderer.GetBehindViewRendering
Glass.Mapper.Sc.Razor.Pipelines.GetRenderer.GetDynamicViewRendering
Glass.Mapper.Sc.Razor.Pipelines.GetRenderer.GetTypedViewRendering
I believe it is this line that bombs (from decompiled source) as Item is null in the case I have.
var renderItem = rendering.Item.Database.GetItem(new ID(rendering.RenderingItemPath));
I am not 100% sure, but I believe this occurs when an invalid datasource is set on the rendering (which is quite easy to achieve in sitecore)
This is low priority.
The Umbraco Unit tests don't work with NCrunch due to the following method in Umbraco:
The Umbraco unit tests do not work with NCrunch, this is due to the following method:
internal static string GetRootDirectorySafe()
{
if (!string.IsNullOrEmpty(IOHelper._rootDir))
return IOHelper._rootDir;
string directoryName = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
IOHelper._rootDir = directoryName.Substring(0, directoryName.LastIndexOf("bin") - 1);
return IOHelper._rootDir;
}
This is called from the Glass.Mapper.Umb.Integration.TestApplicationBase.Start method.
I think the cause of this is the LastIndexOf call, I don't think NCrunch copies files into a bin folder.
I'm using GlassHtml.GetRenderingParameters to map my rendering parameters to an object, but I keep getting an empty object in return.
I've debugged this method and it seems it takes some times for the values to reach the fake object.
The bugged code (from Glass.Mapper.Sc.GlassHtml.GetRenderingParameters):
fakeItem.Editing.BeginEdit();
foreach (string index in parameters.AllKeys) {
fakeItem[index] = parameters[index];
}
T obj = ItemExtensions.GlassCast<T>(fakeItem, false, false);
fakeItem.Editing.CancelEdit();
If I put a Thread.Sleep(50) inside the foreach, it works just fine.
If I put a breakpoint on the GlassCast line and continue from there, it also works fine.
However, if I just put a breakpoint on the CancelEdit() and don't apply any sleep, the object is not populated.
I fixed this by changing the code into this:
fakeItem.Editing.BeginEdit();
foreach (string index in parameters.AllKeys) {
fakeItem[index] = parameters[index];
}
fakeItem.Editing.EndEdit();
T obj = ItemExtensions.GlassCast<T>(fakeItem, false, false);
Not sure if that's the best way, but it works fine for me.
There is another issue with casting rendering parameters.
If you map your Glass models using FieldId instead of FieldNames/AutoMapping, it will not be able to map rendering parameters to the Glass model because of the way they are stored in Sitecore (by field name).
The current type is SitecoreService and not ISitecoreService
I was using Glass.Mapper version 3.0.4.40 and Glass.Mapper.Sc version 3.0.5.52. Now i updated both assemblies to the lastest (3.0.5.49 and 3.0.6.60).
I have a class like that :
[SitecoreType(AutoMap = true)]
public class FredContainer : ContentBase
{
[SitecoreChildren(InferType = true)]
public virtual IEnumerable<ContentBase> Children { get; set; }
[SitecoreParent]
public virtual ContentBase Parent { get; set; }
}
This worked fine with the mentionned assembly but not in the new one. In sitecore, i have an Item that has children. I don't have any class that matches the children because I am only interested in the content inside the children. So I wrote this.MasterService.GetItem(id) to retrieve the parent, then I wrote a loop in all children and another loop for all children's children. The Mapper throws an exception : "Object reference not set to an instance of an object" for the children of the parent.
In the previous version, that same code returned the ContentBase properties and the content was correctly mapped.
I can rollback to the previous version but i'll prefer to stay up to date with the assemblies.
This is the stack trace
[NullReferenceException: Object reference not set to an instance of an object.]
Glass.Mapper.Sc.Pipelines.ObjectConstruction.CreateDynamicTask.Execute(ObjectConstructionArgs args) +37
Glass.Mapper.Pipelines.AbstractPipelineRunner2.Run(T args) +224 Glass.Mapper.AbstractService.InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext) +988 Glass.Mapper.Sc.SitecoreService.CreateType(IEnumerable
1 types, Item item, Boolean isLazy, Boolean inferType, Object[] constructorParameters) +264
Glass.Mapper.Sc.d__2.MoveNext() +322
System.Collections.Generic.List1..ctor(IEnumerable
1 collection) +535
System.Linq.Enumerable.ToList(IEnumerable1 source) +79 Glass.Mapper.Sc.LazyItemEnumerable
1.<.ctor>b__0() +69
System.Lazy1.CreateValue() +14442936 System.Lazy
1.LazyInitValue() +476
Glass.Mapper.Sc.LazyItemEnumerable1.GetEnumerator() +26 System.Linq.Enumerable.Count(IEnumerable
1 source) +224
ImportLogos() in MyProject
This is the method that I use to create the sitecore items.
public void ImportLogos()
{
Container logoRepo = this.ProdService.GetItem<Container>(new Guid(LogosRepositoryId));
Language english = LanguageManager.GetLanguage(LanguageEn);
Language french = LanguageManager.GetLanguage(LanguageFr);
Guid repositoryId = new Guid(LogoRepo);
var repoEn = this.MasterService.GetItem<ContentBase>(repositoryId, english);
var repoFr = this.MasterService.GetItem<ContentBase>(repositoryId, french);
for (int i = 0; i < logoRepo.Children.Count(); ++i) // The logoRepo.Children is NULL.
{
FredContainer FredProductLogo = this.ProdService.GetItem<Container>(logoRepo.Children.ElementAt(i).Id);
foreach (var child in FredProductLogo.Children)
{
Logo myLogo = child as Logo;
if (myLogo == null)
{
continue;
}
var logoEn = this.CreateLogo(myLogo.Id, english, repoEn);
var logoFr = this.CreateLogo(myLogo.Id, french, repoFr);
var logo = logoEn ?? logoFr;
foreach (var logoFile in myLogo.LogoFiles)
{
this.CreateLogoFile(logoFile);
this.CreateLogoFile(logoFile);
}
}
}
}
As you can see, I retrieve the children through the Container, then I use the children to get it's children.
The Container class I have put it in the last mail. This is the ContentBase
[SitecoreType(AutoMap = true)]
public class ContentBase : IContentBase
{
/// <summary>
/// The Name of the Data section of the item.
/// </summary>
[SitecoreField(FieldName = "Name")]
public virtual string DataName { get; set; }
[SitecoreField]
public virtual string Title { get; set; }
[SitecoreId]
public virtual Guid Id { get; set; }
/// <summary>
/// The Name of the Sitecore item.
/// </summary>
[SitecoreInfo(SitecoreInfoType.Name)]
public virtual string ItemName { get; set; }
[SitecoreInfo(SitecoreInfoType.DisplayName)]
public virtual string DisplayName { get; set; }
[SitecoreInfo(SitecoreInfoType.Language)]
public virtual Language Language { get; set; }
[SitecoreInfo(SitecoreInfoType.Url)]
public virtual string Url { get; set; }
[SitecoreInfo(SitecoreInfoType.Version)]
public virtual int Version { get; set; }
[SitecoreInfo(SitecoreInfoType.TemplateId)]
public virtual Guid TemplateId { get; set; }
#region Items Bucket
[DoNotLog]
[SitecoreField(FieldName = "IsBucket")]
public virtual bool IsBucket { get; set; }
/// <summary>
/// Used to know if the item can be contained in a bucket.
/// </summary>
[DoNotLog]
[SitecoreField(FieldName = "Bucketable", FieldId = FredRevampTemplateConstants.Bucketable)]
public virtual bool Bucketable { get; set; }
[DoNotLog]
[SitecoreField(FieldName = "Lock Child Relationship")]
public virtual bool LockChildRelationship { get; set; }
#endregion
}
The real problem is when there's one item in the children that glass doesn't reconize, he will return null instead of only mapping the ContentBase which should be enough in my scenario.
Thank you
Mapper renders rich text fields as editable when not wrapped in Editable tags.
When using
@(Model.FullPath.Contains("sample") ?
Html.Raw(Model.RichTextLeft) :
Editable(x => x.RichTextLeft))
Both fields rendered are editable due to injected mark up.
A workaround for this involved pulling the sample object directly using the following:
@(Model.FullPath.ToLower().Contains("samples") ? Html.Raw(Sitecore.Context.Database.GetItem(new Sitecore.Data.ID(Model.Id)) ["RichTextLeft"]):
Editable(x => x.RichTextLeft))
which returns the rich text field without the editor mark up.
Hello,
When I updated Glass.Mapper.Sc to the most recent version (3.2.0.39 Released June 17, 2014), I noticed that every time I click on Insert Link on any General Link file on the site, I am greeted with an error screen (see below). I see that some MVC pipelines are running despite MVC not being configured.
Thanks!
Server Error in '/' Application.
Could not resolve type name: Glass.Mapper.Sc.Pipelines.Response.GetModel, Glass.Mapper.Sc (method: Sitecore.Configuration.Factory.CreateType(XmlNode configNode, String[] parameters, Boolean assert)).
Description: An unhandled exception occurred.
Exception Details: System.Exception: Could not resolve type name: Glass.Mapper.Sc.Pipelines.Response.GetModel, Glass.Mapper.Sc (method: Sitecore.Configuration.Factory.CreateType(XmlNode configNode, String[] parameters, Boolean assert)).
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[Exception: Could not resolve type name: Glass.Mapper.Sc.Pipelines.Response.GetModel, Glass.Mapper.Sc (method: Sitecore.Configuration.Factory.CreateType(XmlNode configNode, String[] parameters, Boolean assert)).]
Sitecore.Diagnostics.Error.Raise(String error, String method) +129
Sitecore.Configuration.Factory.CreateType(XmlNode configNode, String[] parameters, Boolean assert) +432
Sitecore.Configuration.Factory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert) +67
Sitecore.Configuration.Factory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper) +141
Sitecore.Pipelines.CorePipelineFactory.GetObjectFromType(String type, XmlNode processorNode) +144
Sitecore.Pipelines.CoreProcessor.GetMethod(Object[] parameters) +65
Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +351
Sitecore.Mvc.Pipelines.PipelineService.RunPipeline(String pipelineName, TArgs args) +186
Sitecore.Mvc.Pipelines.PipelineService.RunPipeline(String pipelineName, TArgs args, Func`2 resultGetter) +197
Sitecore.Mvc.Presentation.Rendering.GetModel() +337
Sitecore.Mvc.Presentation.Rendering.get_Model() +27
Sitecore.Mvc.Presentation.ViewRenderer.get_Model() +167
Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer) +158
[InvalidOperationException: Error while rendering view: '/sitecore/shell/client/Speak/Layouts/Layouts/Speak-Layout.cshtml'.
]
Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer) +784
Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Render(Renderer renderer, TextWriter writer, RenderRenderingArgs args) +27
Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Process(RenderRenderingArgs args) +62
(Object , Object[] ) +83
Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +365
Sitecore.Mvc.Pipelines.PipelineService.RunPipeline(String pipelineName, TArgs args) +186
Sitecore.Mvc.Presentation.RenderingView.Render(ViewContext viewContext, TextWriter writer) +294
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +380
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +109 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList
1 filters, ActionResult actionResult) +97
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +879
Passing in null rendering parameters causes and exception to be thrown.
I have not verified if this is simply an issue with checkboxes in general or not so this might affect more then just rendering parameters.
Using Glass and Sitecore MVC 7.2. I have the following (generated) code:
[SitecoreType(TemplateId=IModuleParametersConstants.TemplateIdString)]
public partial interface IModuleParameters : IGlassBase
{
[SitecoreField(IModuleParametersConstants.ShowSeparatorFieldName)]
bool ShowSeparator {get; set;}
}
public static partial class IModuleParametersConstants
{
public const string TemplateIdString = "30e07278-775c-44c4-b558-388ed8b4133c";
public static readonly ID TemplateId = new ID(TemplateIdString);
public const string TemplateName = "Module Parameters";
public static readonly ID ShowSeparatorFieldId = new ID("a1527783-061f-45ab-820d-b8d0ee1300d9");
public const string ShowSeparatorFieldName = "Show Separator";
}
My controller that is used to extract the parameters looks like this:
public abstract class ModuleController<T, TR> : GlassController
where T : AbstractModule<TR>
where TR : class
{
public T Model { get; set; }
private TR _renderingParameters;
public TR RenderingParameters
{
get
{
return _renderingParameters ??
(_renderingParameters = GetRenderingParameters<TR>());
}
set { _renderingParameters = value; }
}
public override ActionResult Index()
{
return View(Model.ViewPath, Model);
}
}
If I check the value of "ShowSeparater" after using the GlassController.GetRenderingParameters collection it is always true, regardless of actual setting. If I use the Sitecore API to access these the value is properly set. So, for now I'm working around this in a slightly hackish way:
var renderingParameters = RenderingParameters;
var rc = Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull.Rendering;
if (null != rc)
{
var parameters = rc.Parameters;
if (null != parameters)
{
if (!rc.Parameters.Contains("Show Separator")) renderingParameters.ShowSeparator = false;
if (String.IsNullOrEmpty(rc["Show Separator"])) renderingParameters.ShowSeparator = false;
RenderingParameters = renderingParameters;
}
}
I believe the issue is in this method: https://github.com/mikeedwards83/Glass.Mapper/blob/master/Source/Glass.Mapper.Sc/GlassHtml.cs#L122
I don't have the solution setup to debug otherwise I'd try to step in and fix the issue and submit a pull request.
The SitecoreFieldIEnumerableMapper reverses order items due to a list.Add instead of list.Insert(0, item)
increase the number of constructor parameters supported from 4 to 10
Issue 20 adds the ability to load an object with multiple interfaces using the ISItecoreService. This needs to be extended to the properties on the created objects.
Currently to get inferred types we have enumerate through the list of configurations instead of looking it up in a dictionary. See TemplateInferredTypeTask
I've run into an issue where my C# field names are camelcase, "SecondaryFeatureImage" and the CMS field names are more user friendly, "Secondary Feature Image" ... it looks like the CMS to C# conversion happens in Glass.Mapper.Sc.Utilities.GetField().
Would it be prudent to add some additional logic to see if the fieldvalue exists with the given name "SecondaryFeatureImage" and if not, attempt to split the camel case? I don't know where else I'd have to set this, I assume there's a SetField() but I haven't done very much digging.
I can certainly do a pull request, this would be simple, but didn't know if this was necessarily a feature you'd want in the main project.
When building the following warning is shown, seems simple enough to resolve and I will attempt to do so if I can get the source to compile locally. In case I can't, here are the details:
App_Start\GlassMapperScRazor.cs(32,21): warning CS0618: 'Glass.Mapper.Sc.Configuration.Attributes.SitecoreAttributeConfigurationLoader'
is obsolete: 'This class is no longer required, use or Glass.Mapper.Configuration.Attributes.AttributeConfigurationLoader or
nothing'
When using SitecoreContext.QueryRelative and there are no results found, a null reference exception occurs when attempting to access the returned IEnumerable. (In sitecore 7.1, probably other versions as well.
This seems to be due to the SelectItems method returning null when there are no results, consequently LazyItemEnumerable cannot run its foreach.
Here is a partial stack trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Glass.Mapper.Sc.d__2.MoveNext() +217
System.Collections.Generic.List1..ctor(IEnumerable
1 collection) +535
System.Linq.Enumerable.ToList(IEnumerable1 source) +79 Glass.Mapper.Sc.LazyItemEnumerable
1.<.ctor>b__0() +145
System.Lazy1.CreateValue() +14276560 System.Lazy
1.LazyInitValue() +476
Glass.Mapper.Sc.LazyItemEnumerable1.GetEnumerator() +82 System.Collections.Generic.List
1..ctor(IEnumerable1 collection) +446 System.Linq.Enumerable.ToList(IEnumerable
1 source) +80
Investigate the possibility of allowing multiple interfaces in object construction. E.g:
var product = _service.GetItem<IProduct, IVat, IComments>("/some path");
The returned product would be a proxied type that combined all of the above.
Is it possible now to make and use another IoC than Castle.Winsor? For example Simple Injector or Unity?
Correct the templates used by razor
Issue with the current compiled expression in Pull 3. It doesn't allow writing to private properties..
The parameterless ctor of the Sitecore GlassController requires for a context item to set the database of the SitecoreContext property.
This always throws an Exception for any requests that don´t set a context item, which is at least the case when custom Mvc routes are implemented (which requires aborting the Sitecore pipeline)
Is there a specific reason that the ContextItem's Database is used? Otherwise, the parameter can be left out, as the parameterless ctor of the SitecoreContext class uses Sitecore.Context.Database.
Name Value Lookup List
Update code gen files as well
Raised by Robert Gray via the Google Group.
Hi,
When I call GlassHtml.RenderImage(MyImage, new ImageParameters { Width = 100, Height = 100 }) I get the invalid markup w="100" h="100" , rather than valid markup width="100" height="100".
The parameters are supplied correclty the Sitecore Image handler (it exects w and h). This is causing problems for me in Chrome. The image is rendered ok in IE 10 & Firefox.
For the time being I am calling this method still and using CSS to control my image size.
Is it possible to have the RenderImage method output the correct and valid attribute names? Also, it'd be great if, when no width and height parameters are supplied, the width and height img attributes are set to be the size of the actual image, as happens currently with the image field render in sitecore.
Check and review how Create and Save methods load types.
I’ve defined some POCOs that derive from Sitecore 7’s SearchResultItem class. I need to do this so that I can use their ObjectIndexKey class in LINQ to Sitecore queries.
As soon as I change the POCOS to inherit from SearchResultItem, Glass throws the exception; otherwise Glass performs as expected.
I suspect that the issue is caused by the following property of SearchResultItem
public virtual object this[ObjectIndexerKey key] { get; set; }
The exception is thrown by this line: context.Load(GlassMapperScCustom.GlassLoaders());
Race condition in the ondemand mapper:
[ArgumentException: An item with the same key has already been added.]
System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +14175344
Glass.Mapper.Context.Load(IConfigurationLoader[] loaders) +371
Glass.Mapper.Pipelines.ConfigurationResolver.Tasks.OnDemandResolver.Configuration OnDemandResolverTask`1.Execute(ConfigurationResolverArgs args) +148
Glass.Mapper.Pipelines.AbstractPipelineRunner`2.Run(T args) +225
Glass.Mapper.AbstractService.InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext) +77
Glass.Mapper.Sc.SitecoreService.GetItem(Guid id, Boolean isLazy, Boolean inferType) +292
Current implemented on Glass.Mapper.Sc.Utilities, more to Glass.Mapper.Utilities
Hi, I haven't been able to reproduce this issue while knowing what exactly I did... but I've seen this a few times now while developing a solution using latest Glass version:
[ArgumentException: An item with the same key has already been added.]
System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +14175344
Glass.Mapper.Context.Load(IConfigurationLoader[] loaders) +371
Glass.Mapper.Pipelines.ConfigurationResolver.Tasks.OnDemandResolver.ConfigurationOnDemandResolverTask`1.Execute(ConfigurationResolverArgs args) +148
Glass.Mapper.Pipelines.AbstractPipelineRunner`2.Run(T args) +225
Glass.Mapper.AbstractService.InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext) +77
Glass.Mapper.Sc.SitecoreService.GetItem(Guid id, Boolean isLazy, Boolean inferType) +292
To me it seem that there could be some kind of concurrency issue in the Glass.Mapper.Context class which I only have seen under application startup. I can see the Context class is not thread safe and the dictionary holding type configurations isn't either. I would suggest using a lazy and thread safe Singleton implementation as seen here: http://www.csharpindepth.com/articles/general/singleton.aspx and the it should be ok not using concurrent dictionaries for the type configurations.
But still I would prefer to have a working way of reproducing this before doing any changes. Have anyone seen this stacktrace before?
Details to follow
I'm just in the process of upgrading a Sitecore project to use Glass.Mapper v3.0.2.5 (from v2.0.11.0). According to tutorial 1 (http://glass.lu/docs/tutorial/sitecore/tutorial01/tutorial01.html) there should be two files installed into the App_Start folder. These files have not been installed by NuGet so I'm now having to create them manually.
Hi Mike,
We've been using the latest Glass Mapper with Umbraco 7 and ran into a problem with the UmbracoPropertyImageMapper. When we call UmbracoService.GetItem<T>(id)
, the Image property fails to map when you create and publish an item. This is the error we get in Visual Studio:
On create and publish, you'll see that the image value is null:
What we've noticed is if you recycle the application pool, the value magically becomes an empty string:
We suspect that on start up, Umbraco is reading these values from the umbraco.config file, which is why the value is an empty string rather than null. Furthermore, we if you call GetModel<T>()
, the property gets mapped correctly and if you take that same content item and call UmbracoService.GetItem<T>(id)
, it fails.
Looking at the source for UmbracoPropertyImageMapper, we think that the culprit is line 57.
Because that value sometimes comes back as null, an exception is thrown and fails to map the model. Hopefully a simple null check is enough to fix the issue.
A client would like to have field mapping errors logged rather than swallowed.
The Glass.Mapper.Sites.Umb
project won't build as various files are missing from the solution
e.g.
All files in the App_Start
folder, the Umbraco database Umbraco.sdf
in the App_Data
folder, all files in the Models
folder etc.
I have an enum type, which the previous version of glass mapper allowed to be stored as a null in the database.
Using the new Glass.Mapper.Sc throws an exception when trying to convert the null value to the enum type.
When you use the RenderLink(navItem, x => x.NavigationLink, contents: navItem.NavigationTitle, isEditable:true) method, the value of the contents parameter is not shown when in Page Editing mode.
In GlassHtml.cs on line 312 it totally ignores the value of the contents parameters and replaces it with "hasChildren=true".
result = MakeEditable(
field,
null,
model,
contents == null ? string.Empty: "haschildren=true",
_context, SitecoreContext.Database, writer);
This doesn't seem like expected behavior to me...
Taken from
https://groups.google.com/forum/#!topic/glassmapper/9tJkBOc8XAE
Hi guys,
I got an null reference exception in the AbstractTypeConfiguration.cs line 102, so I put a simple null check there, and set a break point, the break point is hit.
If I inspect the Mapper properties when the break point is hit, the value is no longer null, but surely it was null previously because the break point is
Then I investigate what sets the Mapper property. It is sets by Glass.Mapper.Context.ProcessProperties() method, which is called by Glass.Mapper.Context.Load() method. This method is called in multiple places and from different threads.
So I put a lock in the Glass.Mapper.Context.Load() method. (The method which set the Mapper property in the Properties collections), and in the Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateConcrete.CreateConcreteTask(), (The method which call MapPropertiesToObject method, which iterates the Properties collection and get the Mapper from it). I test with Jmeter and the exception no longer happens.
My question is where is the best to put the lock or maybe there is a way to avoid the race condition?
Any help or suggestion is much appreciated. Thanks
Since Glass does not use the renderField pipeline unless the page is in editing mode, rendering parameters are not respected.
Example use:
<%=Editable(x => x.PublishDate, new DateParameters {Format = "d"})%>
In Edit mode, this renders properly as a short date. Outside Page Editor, it renders as a long date time string (DateTime.ToString()).
Why doesn't glass just utilize the renderField pipeline at all times? This is what the standard Sitecore controls do, and what other Sitecore "ORMs" do. Otherwise Glass needs to account for any potential rendering parameters that are typically handled by the renderField pipeline.
It looks like there is a race condition in the WindsorConstruction IObjectConstructionTask implementation (Glass.Mapper.Sc.CastleWindsor, 3.1.4.14).
The exception being thrown is a ComponentRegistrationException, which is due to the fact that the same component is being registered more than once in this code. This can happen when multiple glass objects are being constructed for the first time (say, if multiple tabs of the same page are being viewed simultaneously).
My solution has been to put a form of double-checked locking around the component registration, changing the existing code:
To something like:
The cacheKey.GetLock() is my own extension locking mechanism, and I'm not sure if that is appropriate for a pull request, so I hope this explanation suffices.
Let me know if you have any questions, or if there is anything else I can help with.
Add the Resharper Logo to the Glass.Lu website.
Editable(T target, Expression> field, Expression> standardOutput, AbstractParameters parameters)
does not pass the standardOutput parameter to
MakeEditable(Expression> field, Expression> standardOutput, T target)
, it always passes null.
This means that the standardOutput parameter can not be used. Could you fix this please?
Currently the RenderLink helper needs to look like this:
@RenderLink(m => m.Current.Item.ViewLink, new System.Collections.Specialized.NameValueCollection() { { "class", "button animated fadeInUp" } }, true, "LAUNCH SITE")
The syntax could be shortened using the standard Razor "new { }" syntax.
Please implement IDisposable for SitecoreContext and SitecoreService
If a class property has an attribute with a field ID the field ID is ignored in page edit mode.
Error message says it can't convert double instead of integer.
Need to generally improve the field mapping error messages
Below is the reported problem:
I have two languages in sitecore, english (en) and french (fr-CA). I have created two items in the same folder in sitecore, let's say /sitecore/content/folder using the SitecoreService.Create. One is in english (named itemEn), the other is in french (named itemFr). When i query the folder for the itemEn, the service returns it. However, when i use the same query but for the itemFr, the service returns an empty collection.
var service = new SitecoreService("master");
var itemFr = service.Query<GlassBase>("/sitecore/content/folder//*@@name='itemFr']);
itemFr is always empty.
Can you reproduce this behavior?
Is it a problem in my code?
Any help will be appreciated :)
The solution is to added an additional method that allows the language to be specified as a second parameter.
Glass 2 allowed creating items using this syntax:
sitecoreService.Create<ItemType, ParentType>(parentItem, "name");
This was useful if an interface but no class existed for ItemType.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.