Data binding - getBindingContext() returns absolute path rather than relative - sapui5

I've got a table which I'm firing an event on row selection. In the handler I want to get the context for the selected row and then create a new context for a lower level oData object and then bind that to a Text view.
I'm sure there is a beautifully succinct way of doing this but currently I am:
Getting the binding path and adding a string to create a path to my lower level object:
var path = oEvent.getParameters().listItem.getBindingContext().sPath + "/ComplianceNote";
This is returning a path with / as the first character, from what I understand this means it's the root object of the service or this is an "absolute" path. My current workaround is to remove the first character:
path = path.substr(1, path.length);
Then I can bind my Text view:
noteText.bindElement(path);
noteText.bindProperty("text", "Note");
This works fine but seems to me to be a code smell hacking around with the string. My questions are:
Why is the path returned as "absolute" rather than "relative"
What is the correct way to achieve this. I've been looking at things like setBindContext and bindText.
Cheers,
Gregor

Related

Flutter build runner ElementVisitor get path

I am working with Code-Generation and trying to get the path of the Annotated-File.
I would need it inside the visitFieldElement:
#override
dynamic visitFieldElement(FieldElement element) {
// Get path here
}
I tried couple of different things: element.source, elenment.librarySource, element.location.
But non of them is giving me the exact path relativ from lib/.
I know I can simply extract it from e.g the element.location but I thought there must be a cleaner way to get this done.
It should be possible since the builder itself is printing out the path:
Any idea? Let me know if you need any more info!
If you have an element to use via visiting children,
then I believe you do have the "buildStep" variable,
it contains the "path" variable and I think that is what you are looking for.

jsTree: How to *set* opened/selected node by path (not ID)?

So, I can get the full path of a selected node like so (thanks to #ggrandes for that one):
.on('changed.jstree', function (e, data) {
var path = data.instance.get_path(data.node,'/');
console.log('Selected: ' + path);
})
What I now need, is to set select/open a node according to a given path.
All the solutions I've found so far refer to some mysterious ID, which appears to simply assume that the data in question has IDs. My problem is that I don't. It's simply a recursive JSON dict/array describing a directory layout. All I have with each node, is its name and a list of its children (and their names and children and so forth).
So, what I need is something like:
data.instance.set_path('/some/arbitrary/path');
Is it possible to do this with jsTree in some reasonable way?
I ended up creating a full path of every item on the server-side and using that as an ID that could then be selected on the client-side. As far as I can tell, there is no other way, at the time of this writing.

Novacode LineChart type

I have a code that implements a Novacode.LineChart. And the LineChart type which is shown by default is this one:
But I dont want this type of chart, I want it without points, like this:
This is the code where I create the chart:
LineChart c = new LineChart();
c.AddLegend(ChartLegendPosition.Bottom, false);
c.Grouping = Grouping.Stacked;
Anyone knows how can I hide thoose points and show only the lines? Thanks to everyone!!
Your question is shown up while I was searching for the exact same feature. It's probably a bit late but I hope it would be useful for other people in need of this feature.
My so called answer is not more than a few lines of dirty and unmanageable hack so unless you are not in dire need, I do not recommend to follow this way.
I also do not know if is it an approved approach here but I prefer to write the solution step by step so it may help you to grasp the concept and use better methods.
After I have realized that I was unable to use DocX to create a line chart without markers, using currently provided API, I wanted to know what were the differences between actual and desired output. So I saved a copy of .docx file with line chart after I manually edited the chart to expected result.
Before and after the edit
As you may already know, a .docx is a container format and essentially comprised of a few different folders and files. You can open it up with a .zip archive extractor. I used 7-Zip for this task and found chart file at location of /word/charts/chart1.xml but this may differ depending on the file, but you can easily figure it out.
Compared both of chart1.xml files and the difference was, the file without the markers had and extra XML tag with an additional attribute;
<c:marker>
<c:symbol val="none" />
</c:marker>
I had to somehow add this segment of code to chart. I added these up to example code provided by DocX. You can follow up from: DocX/ChartSample.cs at master
This is where the fun begins. Easy part first.
using System.Xml;
using System.Xml.Linq;
using Xceed.Words.NET;
// Create a line chart.
var line_chart = new LineChart();
// Create the data.
var PlaceholderData = ChartData.GenerateRandomDataForLinechart();
// Create and add series
var Series_1 = new Series("Your random chart with placeholder data");
Series_1.Bind(PlaceholderData, "X-Axis", "Y-Axis");
line_chart.AddSeries(Series_1);
// Create a new XmlDocument object and clone the actual chart XML
XmlDocument XMLWithNewTags = new XmlDocument();
XMLWithNewTags.LoadXml(line_chart.Xml.ToString());
I've used XPath Visualizer Tool to determine the XPath query, which is important to know because you can't just add the marker tag to somewhere and expect it to work. Why do I tell this? Because I appended marker tag on a random line and expected it to work. Naive.
// Set a namespace manager with the proper XPath location and alias
XmlNamespaceManager NSMngr = new XmlNamespaceManager(XMLWithNewTags.NameTable);
string XPathQuery = "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser";
string xmlns = "http://schemas.openxmlformats.org/drawingml/2006/chart";
NSMngr.AddNamespace("c", xmlns);
XmlNode NewNode = XMLWithNewTags.SelectSingleNode(XPathQuery, NSMngr);
Now create necessary tags on newly created XML Document object with specified namespace
XmlElement Symbol = XMLWithNewTags.CreateElement("c", "symbol", xmlns);
Symbol.SetAttribute("val", "none");
XmlElement Marker = XMLWithNewTags.CreateElement("c", "marker", xmlns);
Marker.AppendChild(Symbol);
NewNode.AppendChild(Marker);
And we should copy the contents of latest changes to actual XML object. But oops, understandably it is defined as private so it is a read-only object. This is where I thought like "Okay, I've fiddled enough with this. I better find another library" but then decided to go on because reasons.
Downloaded DocX repo, changed this line to
get; set;
recompiled, copied Xceed.Words.NET.dll to both projectfolder/packages and projectfolder/projectname/bin/Debug folder and finally last a few lines were
// Copy the contents of latest changes to actual XML object
line_chart.Xml = XDocument.Parse(XMLWithNewTags.InnerXml);
// Insert chart into document
document.InsertChart(line_chart);
// Save this document to disk.
document.Save();
Is it worth it? I'm not sure but I have learned a few things while working on it. There're probably lots of bad programming practises in this answer so please tell me if you see one. Sorry for meh English.

How to map urls?

I would like to map pages such domain/content/myProject/home.html to domain/home.html. /content/myProject/ is not needed. I have the following code:
String newpath = getResourceResolver().map(page.getPath());
this does not change anything. newpath is stay page.getPath()
how to solve this issue?
Answering as this question as it remains unanswered. Here is an example of how the etc mappings should look like:
Trick is you add 2 entries to sling:internalRedirect as / and /content/example/
AEM first tries to resolve resources with first entry '/'. So non page URLs like /etc/designs, /content/dam etc will be addressed by the first entry. If it is unable to resolve using the first one, it uses the second entry to resolve the page.
This is also the adobe recommended way for URL shortening compared to other techniques like apache redirect.
You need to create map in etc.Then Resource Resolver will take care of trimming the path .
CREATING MAPPING DEFINITIONS IN AEM
In a standard installation of AEM you can find the folder:
/etc/map/http
This is the structure used when defining mappings for the HTTP protocol. Other folders (sling:Folder) can be created under /etc/map for any other protocols that you want to map.
Configuring an Internal Redirect to /content
To create the mapping that prefixes any request to http://localhost:4503/ with /content:
Using CRXDE navigate to /etc/map/http.
Create a new node:
Type sling:Mapping
This node type is intended for such mappings, though its use is not mandatory.
Name localhost_any
Click Save All.
Add the following properties to this node:
Name sling:match
Type String
Value localhost.4503/
Name sling:internalRedirect
Type String
Value /content/
Click Save All.
This will handle a request such as:
localhost:4503/geometrixx/en/products.html
as if:
localhost:4503/content/geometrixx/en/products.html
had been requested.
You can refer here for further documentation http://docs.adobe.com/docs/en/cq/5-6-1/deploying/resource_mapping.html

Getting / ussing full path to find controls in UIA and White

I'm using Microsoft UI automation + White framework. Is it possible to get a full path from to the control from the top parent, and then use it to find an element? For example, use UI spy to get the full path, and then somehow get the control by the taken path?
Thanks
I use the unmanaged version of MSUIA and don't use white, but something like this should do what you are asking. Pass in an element.
CUIAutomation auto = new CUIAutomation();
var desktop = auto.GetRootElement();
var walker = GetRawTreeWalker();
while (true)
{
element = walker.GetParentElement(element);
if (auto.CompareElements(desktop, element) == 1)
{
break;
}
winPath = AppendWinPathPart(winPath, element);
}
AppendWinPathPart is a call to a method that builds something like a path in string form that I use in my automation. It is much like XPath for MSUIA.
I have done something in the past similar to what it sounds like you're trying to do. Unfortunately, it's not necessarily all that easy to do.
I essentially built my own simplified version of UI Spy that used some code similar to what's in the answer from #chrismead above to build a '\' delimited path of automation IDs (unfortunately, as you may have already discovered, AutomationIDs can be unreliable, so for the sake of robustness I also had to add the capability to identify AutomationElements by things like name, position among siblings, or position relative to parent).
Then, I had code in another application that could take those paths as input in order to locate those specific AutomationElements and interact with them.