How to display texts that contain curly braces - sapui5

Is it possible to display a JSON string using e.g. sap.m.Text?
I'm pretty sure it's treating the text as a binding syntax due to the structure of the string "{...}".
I thought there may be a parameter to disable binding allowing any kind of raw text, but looking at the API, I see no such thing.
Here's an example of the issue: http://jsbin.com/zarijedaya/1/edit?html,js,output

You can make use of the setText method which will consider the JSON as a string.
new sap.m.Text().setText(json);
http://jsbin.com/bonoxavilo/1/edit

Texts with curly braces can be escaped via sap.ui.base.ManagedObject.escapeSettingsValue:
new Text({
// ManagedObject required from "sap/ui/base/ManagedObject"
text: ManagedObject.escapeSettingsValue(myJSONText)
});
From API referece:
escapeSettingsValue
Escapes the given value so it can be used in the constructor's settings object. Should be used when property values are initialized with static string values which could contain binding characters (curly braces)
Here is a demo: https://jsbin.com/bocuzaz/edit?js,output
Prerequisite
In order to make escapeSettingsValue work, bootstrap setting compatVersion needs to be set to "edge".

Related

Is empty string value generally allowed by the FIX protocol?

When I look at the definition of a String type in the FIX protocol (e.g. here or here), I don't see a minimum length specified. Is it allowed to use empty strings? One online decoder seems to accept an empty string value (see tag 320), an other complains that it's invalid.
The FIX 4.4 specification states the following (emphasis in the original text):
Each message is constructed of a stream of <tag>=<value> fields with a
field delimiter between fields in the stream. Tags are of data type
TagNum. All tags must have a value specified. Optional fields without
values should simply not be specified in the FIX message. A Reject
message is the appropriate response to a tag with no value.
That strongly suggests (but does not unambiguously state) to me that the use of an empty value for a string is invalid. It is unsurprising to me that different FIX implementations might treat this edge case in different ways. So, I think the best approach is to avoid using empty values for strings.
+1 for Ciaran's and Grant's answer/comments. Just want to add something.
I generally suggest to look up things like this in the most current specification since they usually have been refined/reworded/clarified to eliminate unclear or ambiguous statements from older specs.
The answer is on the very page you link to in your question (emphasis mine, search for "Well-formed field"): https://www.fixtrading.org/standards/tagvalue-online/#field-syntax
A well-formed field has the form:
tag=value<SOH>
A field shall be considered malformed if any of the following occurs as a result of encoding:
the tag is empty
the tag delimiter is missing
the value is empty
the value contains an <SOH> character and the datatype of the field is not data or XMLdata
the datatype of the field is data and the field is not immediately preceded by its associated Length field.

Question mark Typescript variable

I've seen code snippets like these:
export interface IUser {
email?: string;
firstName?: string;
lastName?: string;
}
But why are the variable names suffixed by a question mark? This snippet is part of an example of using mongodb with Typescript.
The answer is probably somewhere out there but I seem to be using the wrong keywords since I can't find it.
In TypeScript, <name>?: <typename> a shorthand for <name>: <typename> | undefined.
This indicates to the type system that a symbol may contain a value of the indicated type or it may contain the value undefined (which is like null).
This is important when the (new in TypeScript 2) --strictNullChecks option is enabled. The documentation on Null- and undefined-aware types option is probably where you should start to understand why this is useful.
It means they can be there but dont have to be. It allows for optional field names. It can be quite common to use.
An example use is allowing users on a website to have an optional display name.
If I am not mistaked, its to indicate that its optional, that means that it can be null.

What is the definition of a 'helper' in CodeMirror registerHelper method

I am looking at CodeMirror help and registerHelper is described as
CodeMirror.registerHelper(type: string, name: string, value: helper)
Registers a helper value with the given name in the given namespace
(type). This is used to define functionality that may be looked up by
mode. ...
http://codemirror.net/doc/manual.html#registerHelper
This does not explain what the value is, when is it called (it seems to be a function), or why getHelpers accepts a position.
Is helper similar to a mode, but providing non-visual annotations (for code lookups)?
It's just a value -- any value. How it will be used depends on the type of helper. For "hint", it'll be a function providing completions at a given point in a document, for "hintWords", it'll be an array of strings that form possible completions, for "wordChars", it is a regular expression describing the characters that count as word characters for a mode, and so on.

Mix #bind and EL expression on a zul

Using ZK 6 I want to do something like this:
<window title="${c:l(#load(vm.name))}">
My goal is to get a label (localization) based on a key that is loaded from my ViewModel and not a static String and this is the problem.
The example given doesn't work because the syntax is invalid but I think you can understand my idea. How to do this in a clean way?
You should use EL expression (including calls of tag library's methods) inside parentheses of annotation and should not enclose it with curly braces:
<window title="#load(c:l(vm.name))">
See EL Expression in Data Binding for more details.

Using gwtquery, how can we select elements with attributes having values containing more than one word?

Say I want to select an element such as
<div class="my class">InnerHTML</div>
While this may be done easily using CSS selectors with [class="my class"], gwtquery has a difference in the sense that it doesn't take the quotation marks in the input. It only accepts values like [attribute=attributevalue].
When I applied the same selector in GQuery with the space in between, it returned no matches. I have a feeling that this might be because of some incorrect parsing in the library for such cases. Is this so?
If so, is there any other way I might select these elements using GQuery?
It works for me (at least with gwtquery-1.1.0 and gwt 2.4.0)
GQuery myClassDivs = $("div[class=\"my class\"]");
returns a match for <div class="my class"/>.
However, with the class attribute, it's generally better to use the ~= selector instead, because <div class="my class"/> and <div class="class my"/> should usually be treated as equivalent.
So I would suggest using
GQuery myClassDivs = $("div[class~=my][class~=class]");
This will also select something like <div class="my class special"/>, which is usually desirable.
Generally, to select attributes with space-separated words, you'll use the [att~=val] selector as mentioned by Chris Lercher.
Or, you know, since you're selecting by the class attribute anyway, you could just use class selectors instead:
GQuery myClassDivs = $("div.my.class");
Regarding this:
When I applied the same selector in GQuery with the space in between, it returned no matches. I have a feeling that this might be because of some incorrect parsing in the library for such cases. Is this so?
If you're referring to adding the space in your unquoted attribute value, it's not a parsing error in the library. The selector itself is invalid because spaces in unquoted attribute values are explicitly invalid.
If quoted attribute values aren't recognized, then that is a parsing error in the library.