Vaadin 23 preformatted text output - vaadin

In Vaadin 8 there is the possibility to show preformatted text with help of the Label component -
Label preLabel = new Label(
"Preformatted text is shown in an HTML <pre> tag.\n" +
"Formatting such as\n" +
" * newlines\n" +
" * whitespace\n" +
"and such are preserved. HTML tags, \n"+
"such as <b>bold</b>, are quoted.",
ContentMode.PREFORMATTED);
https://vaadin.com/docs/v8/framework/components/components-label
How to achieve the same with Vaadin 23 ? I need to pretty print text on the page which contains line breaks \n

The Html class in Flow is intended for freeform HTML content: https://vaadin.com/api/platform/23.1.4/com/vaadin/flow/component/Html.html
Note that the content given to it must be enclosed in a top-level html element, e.g. "<span>Preformatted<b>stuff</b></span>" is ok, while "Preformatted <b>stuff</b>" is not.
If you only need line breaks, however, you could also try the Pre class which renders as a element https://vaadin.com/api/platform/23.1.4/com/vaadin/flow/component/html/Pre.html
E.g. Pre pre = new Pre("This text has line\nbreaks");

Related

Styling a vaadin Component (Dialog) with CSS file

I have a Dialog that retrieve informations from an endpoint (String of information) but I have a Problem with style this dialog, because all these informations appear untidily!
For example to be clear, I have this endpoint, that it helps me to retrieve a Data about Mobile, and want to show this Data in a Dialog (BUT the Style should like Screenshot Nr. 1), but my Problem is that the data appears as Preview (Screenshot 2).
You can use the Html component with a pre tag where you put the formatted JSON:
Html pre = new Html("<pre>" + formattedJson + "</pre>");
To format the JSON String you can use this:
String prettyJson = mapper.writerWithDefaultPrettyPrinter()
.writeValueAsString(mapper.readTree(inputJson));
Find more examples here: https://roytuts.com/how-to-pretty-print-json-in-java/

Is it possible to programatically set the styles in a Vaadin 14 / Flow grid

For example I have a grid where I let the user define the colors for certain data using Vaadin 8 and I'd like to offer this in Vaadin 14 / Flow as well.
In Vaadin 8 I did (for each style/data type):
Page.getCurrent().getStyles()
.add(".MyCustomTheme .v-grid-cell." + cssName + " { background-color:" + userSelectedColor + "; }");
then in the grid code I would do:
addColumn(myColumn).setStyleGenerator(cssName);
In Vaadin 14 / Flow I have:
addColumn(myColumn).setClassNameGenerator(cssName);
However I can't seem to figure out how to programmatically change the css values for cssName. In essence how do I do the first part where I inject my css in the Java code?
Just to add I couldn't do anything as shown here at: https://vaadin.com/docs/v14/flow/element-api/tutorial-dynamic-styling When I tried to do grid.getElement().getStyle().set(...) this would apply to the whole table rather than the rows.
One option is to use TemplateRenderer to inject styles, here is an example.
grid.addColumn(TemplateRenderer.<Bean> of(
"<div style$=\"[[item.styles]]\">[[item.data]]</div>")
.withProperty("styles", "color: red")
.withProperty("data", Bean::getData));
Also note, that Grid's table and its cells are in shadow DOM. So if you are using setClassNameGenerator, you need to set the styles in style module for Grid, instead of global css. I.e. set the generator
grid.addColumn(..).setClassNameGenerator(item -> item.getData() < 0 ? "red" : null);
Add the import for css
#CssImport(value = "my-grid-styles.css", themeFor = "vaadin-grid")
And in "frontend/my-grid-styles.css" use
.red {
color: red;
}
Note, like explained in other answer, you can also set the color to be from css property.
.red {
color: var(--my-grid-cell-color);
}
Then, you can just define the value of that color in Grid scope using (JavaScript call is not needed)
grid.getElement().getStyle().set("--my-grid-cell-color","red");

How do I insert field values from database into an HTML table using Delphi?

I'm generating a HTML order confirmation email using the TIdMessage Indy component in Delphi XE6.
I can add a line to my TIdMessage using:
IdMessage1.Body.Text := '<P STYLE="margin-bottom: 0.2in"><FONT COLOR="#FF0000"><FONT FACE="Calibri"><B> Order Confirmation for Work Order # ' + MyDatasetNameWorkOrder.AsString + '</B></FONT></FONT></P><P STYLE="margin-bottom: 0.2in"><FONT FACE="Calibri">Hello ' + OrdersForm.Proper(ServiceContact1DBText.Field.AsString) + ',</FONT></FONT></P>';`
and then add my HTML head/body sections after those lines, and the resulting email works. It displays the proper Work Order # and Contact when displayed as a HTML email.
But if I add the code above to the body section of my HTML email it doesn't show the table value for the Work Order #, or the Contact person. It just shows the actual text like + MyDatasetNameWorkOrder.AsString + and + OrdersForm.Proper(ServiceContact1DBText.Field.AsString) + in that area of the email.
Do I have to wrap those lines with some other code when trying to embed or insert a database value in a HTML paragraph or table?

Bootstrap Tokenfield does not work in mobile Safari/iOS 8

I am using bootstrap tokenfield to instrument my email textbox to support multiple email input.
User types letter a in the email textbox (the one with red font in the picture) . A list of matched emails show up in a selection menu (the box that shows the email abc#gmail.com in black)
After the user clicks and selected an email, the selected value is not captured. At the end I only got a letter a in the email textbox
How can I fix this issue?
It turns out I am also using Fastclick in my project. It swallowed the click event of the selection menu (of css class tt-selectable) used by bootstrap-tokenfield
At the end it is my solution. Fork the twitter typeahead.js project and change the following line from
$el = $(that.templates.suggestion(context)).data(keys.obj, suggestion).data(keys.val,
that.displayFn(suggestion)).addClass(that.classes.suggestion + " "
+ that.classes.selectable);
to
$el = $(that.templates.suggestion(context)).data(keys.obj, suggestion).data(keys.val,
that.displayFn(suggestion)).addClass(that.classes.suggestion + " "
+ that.classes.selectable + " needsclick");
The additional css class needsclick will disable fastclick on this elements

What's the difference between query(#idname).innerHTML and query(#idname).text

my function look like this:
void write (String message) {
query("#status").innerHTML = message;
query("#head").text = "Click me!";
}
all of them catch id and show text to web browser.
In general browser document model, innerHtml refers to all the internal HTML, whereas text just refers to the text values of the elements. innerHtml is often used by dhtml and Ajax to change a div, where text would be just to set the text value of a single element.
This is more explicitly illustrated when getting, rather than setting, i.e.
e.g. Given:
<div id="idName">
Text in the Div
<p id="anotherId">Inner P</p>
</div>
innerHtml returns
Text in the Div
<p id="anotherId">Inner P</p>
text returns :
Text in the Div
Inner P
If you try this:
String message = """<form method="get" action="#ref"><input name="first_name"/></p><input type="submit" value="Send"/></form>""";
write (message);
then you will appreciate the difference.
The innerHTML should operate an injection of code (an html form in the example) into the HTML page.

Resources