Consider the configuration below:
#URLMapping(id = "programaManter", parentId = "homeTreinamento", pattern = "/programa/#{id : programaManter.id}", viewId = "/pages/treinamento/ProgramaManter.xhtml")
Lets say that I need to navigate to /programa/1. I've tried the following:
return "/pages/treinamento/ProgramaManter.xhtml?faces-redirect=true&id=" + id;
But instead of navigating to /programa/1 it's navigating to /programa/?id=1, how can I force it to build the url using path parameter instead of query parameter?
Solution posted here on the OCPsoft support forums: http://ocpsoft.org/support/topic/navigation-using-path-parameter-on-pretty-faces-2-0-8-final/#post-25822
Related
I created a custom property in the user profile.
I want to search through all the user profiles and output those profiles in which the custom property contains a certain string
For example:
User1- Custom Property value is 1,2,3
User2- Custom Property value in 2,4,5
User3- Custom Property value is 4,6,8
I want to output all the profiles in which Custom Property contains 2
(using c# code)
So the output should have User1 and User2
Can someone suggest the best way to implement this?
I did find some links in the internet for searching user profiles use KeyWord search but and not sure if those methods could be used to search through Custom Properties.
Example: https://www.collaboris.com/how-to-use-search-keywordquery-to-query-user-profiles-in-sharepoint/
I am using SharePoint 2013
We ended up promoting the Custom Property that we added to the User profile to a Managed property.
Also it seems like we can do wildcard searches on managed properties so we do People searches like "CustomProperty:*,2,*" so that it would return all the user profiles which have the number 2 in the custom property of their user profile
Interestingly the wildcard works only on the end for OOTB properties like FirstName so we cant do things like FirstName:oh and expect it would return John Doe's profile
But we can certainly do this - FirstName:joh* and that would return all the people whose first name starts with Joh (which would include John Doe)
But it seems like the wildcard works both at the beginning and the end for the custom managed properties (which helped a great deal for us)
On how to return the results of the search using c# we used this-
private DataTable GetPeople(SPSite spSite, string queryText)
{
var keywordQuery = new KeywordQuery(spSite)
{
QueryText = queryText,
KeywordInclusion = KeywordInclusion.AllKeywords,
SourceId = System.Guid.Parse("b09a7990-05ea-4af9-81ef-edfab16c4e31")
};
keywordQuery.RowLimit = this.MaxProfilesToDisplay;
keywordQuery.SelectProperties.Add("AccountName");
keywordQuery.SelectProperties.Add("PictureURL");
SearchExecutor e = new SearchExecutor();
ResultTableCollection rt = e.ExecuteQuery(keywordQuery);
var tab = rt.Filter("TableType", KnownTableTypes.RelevantResults);
var result = tab.FirstOrDefault();
DataTable DT = result.Table;
return DT;
}
and we would invoke this like
DataTable dt = GetPeople(SPContext.Current.Site, "CustomProperty:*,2,*" );
I am trying to use the wildcard match on routes in FW/1 v 3.5.
Application.cfc
component extends="framework.one" {
this.name= "Wildcard7";
variables.framework = {
home = 'main.home',
action = 'fuseaction',
baseURL = 'useCgiScriptName',
trace = isDebugMode()
};
variables.framework.routes = [
{ "main/home" = "main/home"},
{ "*" = "main/404"}
];
}
When I run the page, without specifying an action, I get the main/404 page instead of main/home
** FW/1 trace**
How can I get main/404 to run only on invalid pages?
When I run the page, without specifying an action, I get the main/404 page instead of main/home
I assume you are trying to access the page like so - your.domain/index.cfm/main. Note the lack of the home action.
Based on your routes, your first route is saying if the path supplied equals "main/home" then point to the view main/home. If there is an action of home in a main.cfc controller then that will be ran prior to rendering the view.
Leaving off the action, home, would not match any of your current routes; resulting in your wildcard catching it. You would need to handle it by including another route like {"main" = "main"}.
UPDATE:
To access main/home from your.domain/index.cfm, you can try passing a route of {"/" = "main/home"}. I would suggest this being above your wildcard and below any other routes to avoid any freak matches.
I've been struggling with this problem the last 2 hours. I'm trying to add a regex-route to my Zend Framework (V1) application. My other routes are static and stored in my application.ini file and that is where i want to put some new regex-routes.
Before i continue to work on more complex regex routes i started to translate the following (working) route to a regex route:
resources.router.routes.shift-display.route = /shift/display/:id
resources.router.routes.shift-display.defaults.module = shift
resources.router.routes.shift-display.defaults.controller = index
resources.router.routes.shift-display.defaults.action = display
Here is what i came up with:
resources.router.routes.shift-display.type = "Zend_Controller_Router_Route_Regex"
resources.router.routes.shift-display.regex = "shift/display/(\d+)"
resources.router.routes.shift-display.defaults.module = shift
resources.router.routes.shift-display.defaults.controller = index
resources.router.routes.shift-display.defaults.action = display
resources.router.routes.shift-display.map.1 = id
resources.router.routes.shift-display.reverse = "shift/display/%d"
But it's not working. It seems the route isn't recognized by the router. When trying to open e.g. vh.localhost/shift/display/7 i get "Invalid controller specified (display)" so the router uses the default route. I also tried to prepend the regex-route with a slash. I tried to use the url-helper to generate links (with passed ID param) using the new regex-route and it works.
Anyone has a clue?
Sometimes is it just that simple. When definining the route, the mistake was made in that line:
resources.router.routes.shift-display.regex = "shift/display/(\d+)"
It has to be
resources.router.routes.shift-display.route = "shift/display/(\d+)"
4 hours for nothing. But at least I finally found it ;-)
Anyone knows how to generate links in sitecore with ID instead of item path?
If you use GetMediaUrl method from the API, I can get this URL:
/~/media/Images/Archive/content/News and Events/News_and_Events_Level2/20070419162739/iwhiz3.jpg
The problem with this approach is that if someone changes the media item name, removes it somewhere or deletes it, the above link will break.
I notice if I insert a media link from rich text editor, I get the link as below:
/~/media/14BDED00E4D64DFD8F74019AED4D74EB.ashx
The second link is better because it's using the item id, so if the actual media item is renamed, removed, or deleted, all related links will be updated too. On top of that, when Sitecore renders the page, it will actually convert the above link and display the item path so it's readable.
I'm using Sitecore 6.5 and currently doing content migration so I need to make sure all internal links are updated properly.
May I know if there is a method to generate the second link by using sitecore API?
Thanks!
The GetMediaItemUrl extension method seems to give you what you want.
public static class ItemExtensions
{
public static string GetMediaItemUrl(this Item item)
{
var mediaUrlOptions = new MediaUrlOptions() { UseItemPath = false, AbsolutePath = true };
return Sitecore.Resources.Media.MediaManager.GetMediaUrl(item, mediaUrlOptions);
}
}
[TestFixture]
public class when_using_items_extensions
{
[Test]
public void a_url_based_on_media_item_id_can_be_generated()
{
// Arrange
Database db = global::Sitecore.Configuration.Factory.GetDatabase("master");
Item item = db.GetItem("/sitecore/media library/Images/MyImage");
// Act
var mediaUrl = item.GetMediaItemUrl();
// Assert
Assert.That(mediaUrl, Is.EqualTo("/~/media/17A1341ABEEC46788F2159843DCEAB03.ashx"));
}
}
These are called dynamic links and you can normally generate them using the LinkManager e.g:
Sitecore.Links.LinkManager.GetDynamicUrl(item)
.. but I'm not sure of the method to do this with Media links (there probably is one but I cant seem to find it and its not on MediaManager) but the basic syntax is:
"/~/media/" + item.ID.ToShortID() + ".ashx"
If you always want to use ID's instead of paths, you can change this setting in webconfig to false (like this):
<setting name="Media.UseItemPaths" value="false"/>`
Here is what the webconfig describes about it:
MEDIA - USE ITEM PATHS FOR URLS
This setting controls if item paths are used for constructing media URLs.
If false, short ids will be used.
Default value: true
Then you can use the default implementation (without additional parameters):
Sitecore.Resources.Media.MediaManager.GetMediaUrl(item);
This is what I use:
var imgField = ((Sitecore.Data.Fields.ImageField)currentItem.Fields["Icon"]);
MediaUrlOptions opt = new MediaUrlOptions();
opt.AlwaysIncludeServerUrl = true;
// Absolute Path works as well. So either use AbsolutePath or AlwaysIncludeServerUrl
opt.AbsolutePath = true;
string mediaUrl = MediaManager.GetMediaUrl(imgField.MediaItem, opt);
I am looking for a quick and dirty way to query the layouts files of a particular page by its friendly url. This is probably easy, but I can't find the solution.
Basically I want to say something like the following. Pseudo-code:
var mainpage = Sitecore.EasyQueryUtility.GetItemByFriendlyUrl(requestedUrl);
or
var mainpage = Sitecore.EasyQueryUtility.GetOppositeOfFriendlyUrl(friendlyurl);
It sounds like you want to do two things here:
Determine an item based on its rendered URL in the address bar (i.e. friendly URL)
Determine the layout being used by the item once you determine the item.
If those are correct, hopefully this can help you out:
Note: untested code I did on-the-fly
// if you have the full URL with protocol and host
public static Item GetItemFromUrl(string url)
{
string path = new Uri(url).PathAndQuery;
return GetItemFromPath(path);
}
// if you have just the path after the hostname
public static Item GetItemFromPath(string path)
{
// remove query string
if(path.Contains("?"))
path = path.split('?')[0];
path = path.Replace(".aspx", "");
return Sitecore.Context.Database.GetItem(path);
}
Once you have the item you can get the layout's name like so:
item.Visualization.GetLayout(Sitecore.Context.Device).Name;
Or the layout's physical file path to the ASPX:
item.Visualization.GetLayout(Sitecore.Context.Device).FilePath;
If you want to get the path of the aspx file which is used for the layout of your page, you can use:
Sitecore.Context.Item.Visualization.Layout.FilePath
I may have misunderstood you but if you want to control the format of friendly URLs you can set several attributes via the Sitecore.Links.UrlOptions class and pass an instance of this in to the link manager. See here for more details. (Note - the LinkManager class is only available from SiteCore 6 I beleive).
The code you would end up with looks like this:
Sitecore.Links.UrlOptions urlOptions = (Sitecore.Links.UrlOptions)Sitecore.Links.UrlOptions.DefaultOptions.Clone();
urlOptions.SiteResolving = Sitecore.Configuration.Settings.Rendering.SiteResolving;
string url = Sitecore.Links.LinkManager.GetItemUrl(item, urlOptions);
You can then set fields like AddAspxExtension on the urlOptions you pass in.
As you can see, the process is reliant on you passing in an item - whether it be obtained via the current context or retrieved from the URL you start off with.
If you were asking about obtaining the layout definition item, take a look at this which shows you how.