I've created a new event handler in my code that looks like this
namespace Utilities
{
public class CustomEvent
{
public void NewEvent_CreateItem(object sender, EventArgs args)
{
//Implementation here
}
}
}
I've add the following to my sitecore.config file
<event name="item:added">
<handler type="Sitecore.Data.Fields.ItemEventHandler, Sitecore.Kernel" method="OnItemAdded" />
<handler type="Utilities.CustomEvent, Utilities" method="NewEvent_CreateItem"/>
<handler type="Sitecore.Caching.Placeholders.PlaceholderCacheEventHandler, Sitecore.Kernel" method="UpdateCaches" resolve="true" />
</event>
However I get the following on my sitecore site:
Could not resolve type name: Utilities.CustomEvent, Utilities (method:
Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode
configNode, String[] parameters, Boolean assert)).
Any ideas?
Thanks
Gemma
I was referring to the the full namespace instead of the project that builds as a dll
so I had
<handler type="Business.Utilities.CustomEvent, Business.Utilities"
method="AcceptClone_SavedItem"/>
instead of
<handler type="Business.Utilities.CustomEvent, Business"
method="AcceptClone_SavedItem"/>
Related
I have an App Route A for a page and is loading all the fields including a multilist that links to Item App Route B that can have in the multilist a link to Item A, creating a infinite loop. Is there a way to set the depth to only one level?
AppRoute A:
fields:
multifield:
AppRoute B
AppRoute B:
fields:
multifield:
AppRoute A
There are two options, you can create a patch for the configuration file to update the layoutService serializationMaxDepth, but this will affect all the Items:
<configuration>
<sitecore>
<settings>
<layoutService>
<serializationMaxDepth>2</serializationMaxDepth>
</layoutService>
</sitecore>
</configuration>
Or you can craete your custom field serialization resolver.
This class will add the information to the field:
public class CustomFieldSerializer : BaseFieldSerializer
{
public CustomFieldSerializer (IFieldRenderer fieldRenderer)
: base(fieldRenderer)
{
}
protected override void WriteValue(Field field, JsonTextWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName(field.Name);
writer.WriteValue("Your custom field value here.");
writer.WriteEndObject();
}
}
This class will be the field resolver:
public class GetCustomFieldSerializer : BaseGetFieldSerializer
{
public GetCustomFieldSerializer(IFieldRenderer fieldRenderer)
: base(fieldRenderer)
{
}
protected override void SetResult(GetFieldSerializerPipelineArgs args)
{
Assert.ArgumentNotNull((object)args, nameof(args));
args.Result = new CustomFieldSerializer(this.FieldRenderer);
}
}
And this is the configuration patch to set the resolver class to your field. Make sure to place your config(patch:before) before the field default serialization configuration, in this case the multililist is GetMultilistFieldSerializer you can check this in https://<your-sitecore-domain>/sitecore/admin/showconfig.aspx:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<group groupName="layoutService">
<pipelines>
<getFieldSerializer>
<processor patch:before="processor[#type='Sitecore.LayoutService.Serialization.Pipelines.GetFieldSerializer.GetMultilistFieldSerializer, Sitecore.LayoutService']" type="Foundation.FieldSerializer.GetCustomFieldSerializer, Foundation.LayoutService" resolve="true">
<FieldTypes hint="list">
<fieldType id="1">multilist</fieldType>
</FieldTypes>
</processor>
</getFieldSerializer>
</pipelines>
</group>
</pipelines>
</sitecore>
</configuration>
I'm facing a problem in my Sitecore project. As we are working in a team, we can't track all the item who has created and what name they have given. The problem is, people are creating the item with same name. This is causing some serious problem while moving the items to different environments.
What I want is, while creating the Sitecore item, pipeline method should execute and validate whether its immediate parent already has the same item name.
For example : Parent A has 3 subitems called Child1, Child2, Child3, when developer tried to create a item with name Child2 the popup/alert should display and not to allow him to create the item.
Please help me with this.
You can add your own handler to item:creating event and check if the parent already contains a child with proposed name.
Here is nice post describing how to prevent duplicates items in Sitecore. I've copied the following code from there:
<event name="item:creating">
<handler type="YourNameSpace.PreventDuplicates, YourAssembly" method="OnItemCreating" />
</event>
namespace YourNamespace
{
public class PreventDuplicates
{
public void OnItemCreating(object sender, EventArgs args)
{
using (new SecurityDisabler())
{
ItemCreatingEventArgs arg = Event.ExtractParameter(args, 0) as ItemCreatingEventArgs;
if ((arg != null) && (Sitecore.Context.Site.Name == "shell"))
{
foreach (Item currentItem in arg.Parent.GetChildren())
{
if ((arg.ItemName.Replace(' ', '-').ToLower() == currentItem.Name.ToLower())
&& (arg.ItemId != currentItem.ID))
{
((SitecoreEventArgs)args).Result.Cancel = true;
Sitecore.Context.ClientPage.ClientResponse.Alert
("Name " + currentItem.Name + " is already in use.Please use another name for the page.");
return;
}
}
}
}
}
}
}
I have a blog post out for this which uses the item create / save event and uses index search to identify duplicates. This was implemented and tested with Sitecore 7.2. Here's the config used:
<sitecore>
<events>
<event name="item:creating">
<handler type="MySite.Customizations.Customized_Sitecore.UniqueItemNameValidator, MySite" method="OnItemCreating" />
</event>
<event name="item:saving">
<handler type="MySite.Customizations.Customized_Sitecore.UniqueItemNameValidator, MySite" method="OnItemSaving" />
</event>
</events>
</sitecore>
When I run in the simulator it works, but in tablets, smartphones, etc., I get "Reference Error - Tizen is not defined."
My main:
//Initialize function
var init = function () {
// TODO:: Do your initialization job
console.log("init() called");
// add eventListener for tizenhwkey
document.addEventListener('tizenhwkey', function(e) {
if(e.keyName == "back") {
alert(tizen.application);
tizen.application.getCurrentApplication().exit();
}
});
notificationMe = function () {
try {
console.log(tizen.application);
window.tizen.alarm.removeAll();
var appControl = new window.tizen.ApplicationControl("http://tizen.org/appcontrol/operation/view");
var alarm = new window.tizen.AlarmAbsolute(new Date(2014, 1, 27, 10, 20));
window.tizen.alarm.add(alarm, tizen.application.getCurrentApplication().appInfo.id, appControl);
alert('Prepare to Tizen Alert');
alert(alarm.getNextScheduledDate()+" - "+window.tizen.alarm.getAll().length);
} catch(err) {
alert(err.name+" : "+err.message);
}
}
};
$(document).ready(init);
config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets" id="http://yourdomain/Alarm" version="1.0.0" viewmodes="maximized">
<tizen:application id="___ID_OCULTED__" package="__OCULTED__" required_version="2.0"/>
<content src="index.html"/>
<feature name="http://tizen.org/api/tizen"/>
<feature name="http://tizen.org/api/application"/>
<feature name="http://tizen.org/api/application.kill"/>
<feature name="http://tizen.org/api/application.launch"/>
<feature name="http://tizen.org/api/application.read"/>
<feature name="http://tizen.org/api/alarm"/>
<feature name="http://tizen.org/api/alarm.read"/>
<feature name="http://tizen.org/api/alarm.write"/>
<icon src="icon.png"/>
<name>Alarm</name>
<tizen:privilege name="http://tizen.org/privilege/application.launch"/>
<tizen:privilege name="http://tizen.org/privilege/alarm"/>
<tizen:privilege name="http://tizen.org/privilege/notification"/>
<tizen:privilege name="http://tizen.org/privilege/application.read"/>
<tizen:privilege name="http://tizen.org/privilege/application.info"/>
<tizen:setting screen-orientation="portrait" context-menu="enable" background- support="disable" encryption="disable" install-location="auto" hwkey-event="enable"/>
</widget>
Any suggestions?
I tried tizen, window.tizen ... no effect on tables, smartphones, but in the simulator it still work.
Just disable checkbutton "Enable Live Editing" in "Run Configurations" menu (rigth click on project -> "Run as" -> "Run configurations...")
P.S.
The same problem in: Tizen SDK: Can't find variable: tizen
Check for tizen object in js console. If it is undefined, reinstall wrt-plugins-tizen packages.
Logs from js console (debug) would be helpful...
Most probably you're running that on devices that doesn't support Tizen.
Even now there's only a handful of devices that support Tizen.
I know only Samsung smartwatches Gear 1 & 2 & S and "experimental" smartphone Samsung Z1.
I need to create a Sitecore include patch file to add a string to the existing value attribute of the IgnoreUrlPrefixes setting in the web.config.
I have tried to overwriting the default ignored prefixes entirely with the following include file:
<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<settings>
<setting name="IgnoreUrlPrefixes">
<patch:attribute name="value">/foo/|/sitecore/default.aspx|/trace.axd|/webresource.axd|/sitecore/shell/Controls/Rich Text Editor/Telerik.Web.UI.DialogHandler.aspx|/sitecore/shell/applications/content manager/telerik.web.ui.dialoghandler.aspx|/sitecore/shell/Controls/Rich Text Editor/Telerik.Web.UI.SpellCheckHandler.axd|/Telerik.Web.UI.WebResource.axd|/sitecore/admin/upgrade/|/layouts/testing</patch:attribute>
</setting>
</settings>
</sitecore>
</configuration>
</settings>
Where /foo/ is the url prefix that I would like to add to the default prefixes. ShowConfig.aspx identifies that the modified configuration has not been applied.
Ideally I would like to be able to simply add /foo/ to whatever exists as the default IgnoreUrlPrefixes values. Does anyone know if this is possible and how to specify it in Sitecore patch syntax?
Good explanation of all possibilities of Sitecore include config files can be found in this John West blog post.
As you can find in the linked post:
patch:attribute: Define or replace the specified attribute.
It does not allow to "add /foo/ to whatever exists as the default IgnoreUrlPrefixes" attribute.
I recently ran into this same issue and it seems like Mark Ursino posted a blog on this particular issue:
http://firebreaksice.com/sitecore-patchable-ignore-lists/
In his example, he executes a custom pipeline after the default Sitecore one to update the value.
So instead, I’ve created a new pipeline processor that comes after the
built-in one (which will support the existing native IgnoreUrlPrefixes
setting) and will allow you to add each path via its own XML config
node. The advantage here is you can patch and continue to patch on
without needing to copy the existing values.
Sample patch file:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<httpRequestBegin>
<processor type="Sitecore.PatchableIgnoreList.ProcessPatchedIgnores, Sitecore.PatchableIgnoreList"
patch:after="processor[#type='Sitecore.Pipelines.HttpRequest.IgnoreList, Sitecore.Kernel']">
<Paths hint="list:AddPaths">
<foo>/foo</foo>
<bar>/bar</bar>
</Paths>
</processor>
</httpRequestBegin>
</pipelines>
</sitecore>
</configuration>
Source code for the pipeline processor, from the blog:
using Sitecore.Collections;
using Sitecore.Pipelines.HttpRequest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Sitecore.PatchableIgnoreList
{
public class ProcessPatchedIgnores : HttpRequestProcessor
{
private List<string> _paths = new List<string>();
public override void Process(HttpRequestArgs args)
{
string filePath = args.Url.FilePath;
foreach (string path in _paths)
{
if (filePath.StartsWith(path, StringComparison.OrdinalIgnoreCase))
{
args.AbortPipeline();
return;
}
}
}
public void AddPaths(string path)
{
if (!string.IsNullOrEmpty(path) && !_paths.Contains(path))
{
_paths.Add(path);
}
}
}
}
I have a Web Service which I am trying to Autowire a variable into. Here is the class:
package com.xetius.isales.pr7.service;
import java.util.Arrays;
import java.util.List;
import javax.jws.WebService;
import org.springframework.beans.factory.annotation.Autowired;
import com.xetius.isales.pr7.domain.PR7Product;
import com.xetius.isales.pr7.domain.PR7Upgrade;
import com.xetius.isales.pr7.logic.UpgradeControllerInterface;
#WebService(serviceName="ProductRulesService",
portName="ProductRulesPort",
endpointInterface="com.xetius.isales.pr7.service.ProductRulesWebService",
targetNamespace="http://pr7.isales.xetius.com")
public class ProductRulesWebService implements ProductRulesWebServiceInterface {
#Autowired
private UpgradeControllerInterface upgradeController;
#Override
public List<PR7Product> getProducts() {
if (upgradeController == null) {
return Arrays.asList(new PR7Product("Fail"));
}
return upgradeController.getProducts();
}
#Override
public List<PR7Upgrade> getUpgrades() {
if (upgradeController == null) {
return Arrays.asList(new PR7Upgrade("Fail"));
}
return upgradeController.getUpgrades();
}
#Override
public List<PR7Product> getProductsForUpgradeWithName(String upgradeName) {
if (upgradeController == null) {
return Arrays.asList(new PR7Product("Fail"));
}
return getProductsForUpgradeWithName(upgradeName);
}
}
However, when I try to access the web service I am getting the Fail version returned, meaning that upgradeController is not being autowired. Here is my applicationContext:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.xetius.isales.pr7" />
<context:annotation-config />
<bean id="upgradeController" class="com.xetius.isales.pr7.logic.UpgradeController" />
</beans>
How do I make it so that the #WebService class is spring aware and autowiring happens
If you want autowiring to happen, ProductRulesWebService needs to extend SpringBeanAutowiringSupport
Extending that class will allow UpgradeController to be autowired
Use a stack like CXF, which supports Spring natively, then you can essentially do something like this:
<bean id="aService" class="com.xetius.isales.pr7.service.ProductRulesWebService " />
<jaxws:endpoint id="aServiceEndpoint" implementor="#aService" address="/aService" />
Depending on container version or even the Spring, hereinafter you will have an easy solution to expose your WSDL, use:
#PostConstruct
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);