Failure to render B64encoded Thymeleaf - image

I have searched many hours on here and across the Internet an am unable to render a properly B64 encoded image in an object. I have tried every permutation of diacriticals and nothing. Can someone inform the correct
<tr th:each="re:${reorderList}">
<td th:text="${re.invoiceNum}"></td>
<td th:text="${re.ordered}"></td>
<td th:text="${re.shipped}"></td>
<td th:text="${re.sku}"></td>
<td ><img th:src="${'data:image/jpg;base64,'+ re.upc_s" ></td>
<td th:text="${re.upc01_s}"></td>
<td th:text="${re.brand}"></td>
<td th:text="${re.desc}"></td>
<td th:text="${re.stdCost}"></td>
</tr>

You're missing the ending curly brace in the th:src attribute of your <img /> tag. The expression should be:
th:src="${'data:image/jpg;base64,'+ re.upc_s}"
I would personally represent this as:
<img th:src="|data:image/jpg;base64, ${re.upc_s}|" />

Related

xpath that exclude some specific elements

This is a simple version of the HTML of the page that I want analyse:
<table class="class_1">
<tbody>
<tr class="class_2">
<td class="class_3"> </td>
<td class="class_4"> </td>
<td class="class_5"> </td>
</tr>
<tr class="class_2">
<td class="class_3"> </td>
<td class="class_4"> </td>
<td class="class_5"><span class="class_6"></span>square</td>
</tr>
<tr class="class_2">
<td class="class_3"> </td>
<td class="class_4"> </td>
<td class="class_5"><span class="class_7"></span>circle</td>
</tr>
<tr class="class_2">
<td class="class_3"> </td>
<td class="class_4"> </td>
<td class="class_5"><span class="class_6"></span>triangle</td>
</tr>
</tbody>
</table>
You can find the page at
https://sabbiobet.netsons.org/test.html
If you try in a google sheets the function:
=IMPORTXML("https://sabbiobet.netsons.org/test.html";"//td[#class='class_5']")
i'll obtain:
square
circle
triangle
I need to obtain all the <td> with class="class_5" minus the ones that have or <span class=class_7>.
In other words I want to obtain only these values:
Square
Triangle
can somebody help me?
The following XPath expression
//td[#class='class_5' and span and not(span[#class='class_7'])]
selects all td elements having an attribute class with value class_5, having a child element span and not having a child element span where its class attribute has the value class_7.
Note that you could also use
//td[#class='class_5' and span[#class='class_6']]
to get the same result in this case.
This should work:
//td[#class='class_5'][not(text()=' ')][not(./span[#class='class_7'])]
where [not(text()=' ')] is not testing for a reqular space but rather for a symbol with Unicode code U+00A0 that you can input from keyboard in windows using alt+0160 where numbers are to be input from numpad.

How to remove tag span, space, new line character in Thymeleaf conditional code block?

I am using Spring Boot 2.1.5.RELEASE, Thymeleaf 3.0.11.RELEASE (thymeleaf-3.0.11.RELEASE.jar), Thymeleaf Spring 3.0.11.RELEASE (thymeleaf-spring5-3.0.11.RELEASE.jar)
code snippet
<tr th:each="employee : ${employeeList}">
<td th:text="${employee.order}"></td>
<td th:text="${employee.age}"></td>
<td th:switch="${employee.level}">
<span th:case="0">Junior</span>
<span th:case="1">Senior</span>
<span th:case="2">Expert</span>
</td>
<td th:text="${employee.activeStatus}"></td>
</tr>
For sorting in data-grid by JavaScript, I need remove <span></span> tag pairs. For example, if an employee has level = 2. This time, Thymeleaf will render
<td><span>Expert<span></td>
I hope it become to
<td>Expert</td>
(without <span> tag). How to to this?
I also try
<tr th:each="employee : ${employeeList}">
<td th:text="${employee.order}"></td>
<td th:text="${employee.age}"></td>
<td th:switch="${employee.level}">
<th:block th:case="'0'">Junior</th:block>
<th:block th:case="'1'">Senior</th:block>
<th:block th:case="'2'">Expert</th:block>
</td>
<td th:text="${employee.activeStatus}"></td>
</tr>
But It generate unwanted character
<td>
Expert
</td>
(Has new line or space before text, It is not wanted result)
The answer is, you shouldn't care about the extra spaces & newlines. HTML ignores those spaces when rendering, and so it shouldn't matter to you -- and there is no way to get rid of them short of formatting hacks.
If you really want to get rid of the spaces you could:
Put the switch on one line.
<tr th:each="employee : ${employeeList}">
<td th:text="${employee.order}"></td>
<td th:text="${employee.age}"></td>
<td th:switch="${employee.level}"><th:block th:case="'0'">Junior</th:block><th:block th:case="'1'">Senior</th:block><th:block th:case="'2'">Expert</th:block></td>
<td th:text="${employee.activeStatus}"></td>
</tr>
Create a Map<String, String> levelToDescription, put it on the model, and use that instead of a switch statement.
<tr th:each="employee : ${employeeList}">
<td th:text="${employee.order}" />
<td th:text="${employee.age}" />
<td th:text="${levelToDescription[employee.level]}" />
<td th:text="${employee.activeStatus}" />
</tr>
Etc...
Replace
<td th:switch="${employee.level}">
<th:block th:case="'0'">Junior</th:block>
<th:block th:case="'1'">Senior</th:block>
<th:block th:case="'2'">Expert</th:block>
</td>
by
<th:block th:if="${employee.level} eq '0'"><td>Junior</td></th:block>
<th:block th:if="${employee.level} eq '1'"><td>Senior</td></th:block>
<th:block th:if="${employee.level} eq '2'"><td>Expert</td></th:block>

Combine th:each with templating element using Thymeleaf

I have a list of 'product' which I want to show as a list of row table using an html template.
The html template looks like:
<tr th:fragment="productTemplate">
<td th:text="${productName}">product name</td>
<td th:text="${productprice}>product price</td>
</tr>
Here is what I did:
<table>
<tr th:each="product : ${products}" th:substituteby="product :: productTemplate" th:with="productName=*{name}, productPrice=*{price}" />
</table>
If I use th:include, there will be tr nested to each tr
If I use th:substituteby, substitute has the priority on th:each
I cant find a way to replace my loop items by an other.
Somebody have a solution to do this?
I got it:
<table>
<tr th:each="product : ${products}" th:include="product :: productTemplate"
th:with="productName=${product.name}, productPrice=${product.price}"
th:remove="tag" />
</table>
And here, we can keep the template class on the tr element (that what I wanted)
<tbody th:fragment="productTemplate">
<tr class="my-class">
<td th:text="${productName}">product name</td>
<td th:text="${productPrice}">product price</td>
</tr>
</tbody>
here's the result:
<table>
<tr class="my-class">
<td>Lettuce</td>
<td>12.0</td>
</tr>
<tr class="my-class">
<td>Apricot</td>
<td>8.0</td>
</tr>
</table>
thanks to danielfernandez from the official thymeleaf forum
th:include is what you are looking for. The code below works for me. I prefer to put multiple fragments in one file so I've included that here.
<table>
<tr th:each="product : ${products}" th:include="/fragments/productFragment :: productRow" />
</table>
...
/fragments/productFragment.html
...
<tr th:fragment="productRow">
<td th:text="${product.productName}">product name</td>
<td th:text="${product.productPrice}">product price</td>
</tr>
...

How to use "selenium-webdriver-xpath" to get the text value from <td>?

Find the below html code:
<table id="supplier_list_data" cellspacing="1" cellpadding="0" class="data">
<tr class="rowLight">
<td class="extraWidthSmall">
Cdata
</td>
<td class="extraWidthSmall">
xyz
</td>
<td class="extraWidthSmall">
ppm
</td>
</tr>
</table>
Now using xpath how to get the value xyz (means always the second "<td>") . Give me an idea please!
Try //tr/td[2]/data().
//tr/td selects all <td/> elements, [2] the second result inside each <tr/> and data() returns their contents.

Finding table values in watij using xpath

I am using watij to automate my UI testing. I have many tables in a webpage. I need to find a table which has a width 95%. It contains many rows. I have to find each row with different text say "running first UI test on local" as below adn need to get the td value "Complete". I am not ble to get the value but I get the watij address. Let me know how I can find this.
<table width=95%>
<tr>
<th align="left">
<span id="lblHeaderComponent" style="font-size:10pt;font-weight:bold;">Component</span>
</th>
<th align="left">
<span id="lblHeaderServer" style="font-size:10pt;font-weight:bold;">Server</span>
</th>
<th align="left">
<span id="lblHeaderStatus" style="font-size:10pt;font-weight:bold;">
</span>
</th>
</tr>
<tr>
<td align="left"
nowrap="nowrap" style="font-size:12px;">running first UI test on local</td>
<td align="left" style="font-size:12px;">Google</td>
<td align="left" style="font-size:12px;">
<a style='color:#336600;'>Complete</a>
</td>
</tr>
<tr>
<td align="left"
style="border-top:1px solid #cfcfcf;border-bottom:1px solid #cfcfcf;"
colspan="3"
style="font-size:12px; color:#ff3300;">
</td>
</tr>
<tr>
<td align="left" nowrap="nowrap" style="font-size:12px;">running second UI test on local</td>
<td align="left" style="font-size:12px;">Google</td>
<td align="left" style="font-size:12px;">
<a style='color:#336600;'>Complete</a>
</td>
</tr>
</table>
You can try an xpath visualizer like this one to assist you in getting the right expression. It lets you see the results visually.
Using XPath on HTML assumes the HTML is XHTML - in other words it must be well-formed XML.

Resources