Please help, i cann't find in freemarker guide how to convert from thymeleaf this:
lists.isEmpty and for each
<th:block th:if="${#lists.isEmpty(employees)}">
<h3>No employee</h3>
</th:block>
<th:block th:unless="${#lists.isEmpty(employees)}">
<tr th:each="contact,iterStat : ${employees}">
<td th:text="${iterStat.count}"></td>
<td th:text="${contact.name}"></td>
<td th:text="${contact.phone}"></td>
Thanks!
Maybe Something like this? (sketch, not tested)
<#list employees as contact>
<tr>
<td>${contact?index}
<td>${contat.name}</td>
<td>${contact.phone}</td>
</tr>
<#else>
<h3>No employee</h3>
</#list>
Notes
<#list> Will generate a <tr> element for each item in the employees sequence, containing <td>'s for each field.
If the employees sequence is empty it will generate the <h3> element.
See List Directive Doc
It gets the zero based index of the item using the build-in function
?index. See built-ins and loop variables in the help. Freemarker built-ins Doc. If you want one based, you can add one to it.
It's works
<#list employees as contact>
<tr>
<td>${contact?index}
<td>${contat.name}</td>
<td>${contact.phone}</td>
</tr>
<#else>
<h3>No employee</h3>
</#list>
Related
Our old internet site was getting data from a database and was having HTML tags inside text that was formatting text in the site. I explain.
When I was calling the database to have the text of the field INFO.
The text was:
"List of available city:<br>1-Boston<br>2-Washington<br>3-Miami... etc"
So in the old site when I was using my table It was like this:
<table>...
<td><%= INFO %> </td>
So the site was formatting the text inside the TD field and was giving the list of the city in the cell field of the table like this:
List of available city:
1-Boston
2-Washington
3-Miami
Now we're using Angular and Mat-Table to create a new site. The information is coming from the same database having text already formatting with some HTML tags.
If I use this code:
<table>
<tr *ngFor="let rule of element.Reglements">
<td class="line_rules">{{ rule.Reglement }}</td>
</tr>
</table>
Unfortunately the result in the cell gives a text including the HTML tags like this:
"List of available city:<br>1-Boston<br>2-Washington<br>3-Miami... etc"
Question: How can I format my Table cell to use the HTML tags ?
Do I need to change the HTML tags for something else ? (I can directly modify the database or loop though field and replace code before passing data to the table ?
Is there a way to insert line feed in a text cell ?
Thanks
I found something to do this.
My code was:
<table>
<tr *ngFor="let rule of element.Reglements">
<td class="line_rules">{{ rule.Reglement }}</td>
</tr>
</table>
I do it like this:
<table>
<tr *ngFor="let rule of element.Reglements">
<td class="line_rules" [innerHTML]="rule.Reglement"></td>
</tr>
I have a list in Thymeleaf and I want to use th:with in a div to grab the last element in a list. I've tried:
<div th:if="${not #lists.isEmpty(licence.registrations)}"
th:with="lastRegistation=${licence.registrations[__(#lists.size(licence.registrations) - 1)__]}">
<tr>
<td>Name</td>
<td><span th:text="${lastRegistration.name}"/></td>
</tr>
</div>
However this gives me the error:
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "(#lists.size(licence.registrations) - 1)" (template: "admin/viewLicence.html" - line 103, col 10)
Does anyone know a way I can get the last item in a list with Thymeleaf?
Cheers,
Neil
If you're using preprocessing, you need to surround the expression with ${...}. Like this:
th:with="lastRegistration=${licence.registrations[__${#lists.size(licence.registrations) - 1}__]}"
That being said, there is no reason to use preprocessing in this case. (And I would remove the extra unused tags as well.) This will work:
<tr th:if="${not #lists.isEmpty(licence.registrations)}"
th:with="lastRegistration=${licence.registrations[#lists.size(licence.registrations) - 1]}">
<td>Name</td>
<td th:text="${lastRegistration.name}" />
</tr>
You can also get fancy with collection selection & projection, but I'm not sure this is an appropriate use. Still, it seems to work:
<tr th:if="${not #lists.isEmpty(licence.registrations)}">
<td>Name</td>
<td th:text="${licence.registrations.![name].$[true]}" />
</tr>
With the help of firePath, I got this:
.//*[#id='#table-row-51535240d7037e70b9000062']/td[1]
Parot of My HTML looks like this:
<table class="table table-bordered table-striped">
<tbody>
<tr>
<tr>
<tr id="#table-row-51535240d7037e70b9000062"> #this is the id that i want to get
<td> 54 </td> #this is the td that i know
<td>
<td>
<td>Open</td>
<td/>
What i really want to do here is, by giving the td value (54), I want to be able to get the id (parse the id), any hints how can i achieve that?
Thanks in advance.
PS: sorry for my English, and for my lack of knowledge :)
First of all your HTML is invalid (because it contains nested <tr> nodes). Nokogiri may be able to parse it, but if you can you should fix it before that.
You can fetch that id by the following ruby code:
doc.at_xpath("//td[contains(text(), '54')]/..")['id']
//td[contains(text(), '54')] will grab all the <td> nodes which contain 54, /.. will go to their parents.
Document#at_xpath will fetch only the first matching item
['id'] will get the attribute of the matching node.
Using jquery
$(function(){
// (i dont know if you have id for that td or not, it will be more easy if u do have id for that td)
console.log($('table tbody tr td:first').closest('tr').attr('id')); // you can remove :first if you want to.
});
Oops, I misread your question, and one more thing, there is a problem in your tr tag.
I have the following HTML snippet:
<divv id="items">
<trr>
<td>
<p>Cars</p>
<a>Toyota</a>
<a>Opel</a>
<a>Audi</a>
</td>
</tr>
<tr>
<td>
<p>Planes</p>
<a>A320</a>
<a>B787</a>
<a>B767</a>
</td>
</tr>
<div/>
What I want is to create a XPath query so I can retrieve only the Cars.
Currently I am using this: //div[#id='items']/tr/td. But with this I get also the Plane items. I do not know how to test for the 'p' tag.
Anyone can help me ?
Thanks.
//div[#id='items']/tr/td[p='Cars']
The last predicate tests the existence of a <p> child element with Cars text content and thus filters out the <td> with <p>Planes</p>.
If picking the first group is enough, then you can use:
//div[#id='items']/tr/td[1]
I have the following HTML code :
<table class="report" width="100%">
<thead>
</thead>
<tbody>
<tr class="alt">
<td>
<a onclick="window.open(this.href);return false;" href="/search/searches/1563/reports/946">56175-746-45619568-noor.fli.zip</a>
</td>
<td class="_"> Report </td>
<td class="_"> 09 Apr 2012</td>
<td class="_"> Noor</td>
<td class="_"> 2.8 MB</td>
<td class="_">Ready</td>
</tr>
I want to click on href="/search/searches/1563/reports/946">56175-746-45619568-noor.fli.zip but I do not want to use XPATH. I tried a lot of things but failed, is there a way to click on this href without using XPATH. Thanks a lot.
You can use the href
br.link(:href => '/search/searches/1563/reports/946').click
or the text
br.link(:text => '56175-746-45619568-noor.fli.zip').click
or you can use variations with regex matches
br.link(:href => /reports/).click
or
br.link(:text => /noor.fli.zip/).click
Is it the only link in that table? or always the first link in that table?
browser.table(:class => 'report').a.click
If there are multiple tables, then you have to figure out how to find the one you want. perhaps by the text inside the table. If in your example the text Noor is unique to that table, then you could try something like this
browser.table(:class => 'report', :text => /Noor/).a.click
or if you know the structure above will persist where the link and the info about the report are on a single table row)
browser.row(:text => /Noor/).a.click
You'd have to try to decide which is going to be the most robust or least brittle