Thymeleaf. How to hide element based on boolean parametr? - java

I have a table of reviews
<table class="table">
<tbody>
<tr th:each="review : ${reviewsForMovie}">
<td th:utext="${review.text}"></td>
</tr>
</tbody>
</table>
But I dont want to show review if review.isApproved == false
How do i do that?

<table class="table">
<tbody>
<tr th:each="review : ${reviewsForMovie}">
<td th:hidden="${!review.isApproved}" th:utext="${review.text}"></td>
</tr>
</tbody>
</table>

Related

Insert table as fragment with parameters

I have a table and fragment on on childFragment.html
<div th:fragment="firstTable">
<table border="2">
<tbody>
<tr th:each="rt : ${fragment}">
<td th:text="${rt.id}"></td>
<td th:text="${rt.number}"></td>
<td th:text="${rt.number2}"></td>
</tr>
</tbody>
</table>
</div>
How can I insert it in the another html page?

how to know which button is clicked in jsp foreach loop

I have a JSP page that's attached to a list of objects I need to loop through using a JSTL loop. Basically, I want it to display different information about the book and a submit input view (send to another jsp page to see more details about the book).
My question is how can I know which button was clicked and how can I recover the corresponding book.
<table class="table table-striped">
<thead>
<tr>
<th scope="col">N°</th>
<th scope="col">Title</th>
<th scope="col">ISBN</th>
<th scope="col">Author</th>
<th scope="col">Year</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row"></th>
<c:set var="count" value="${1}" scope="request"/>
<c:forEach items= "${requestScope.booksList}" var="b">
<tr>
<td>${count }</td>
<td> ${b.getTitle() } </td>
<td> ${b.getISBN() } </td>
<td> ${b.getAuthor() } </td>
<td> ${b.getYear() } </td>
<td><input type="submit" value="View" name="View${count }"></td>
<td><input type="submit" value="Mark" name="Mark"></td>
</tr>
<c:set var="count" value="${count + 1}" scope="request" />
</c:forEach>
</tr>
</tbody>
</table>

How to hide table rows when the value is null

I am creating a project in eclipse where I want to display values input into a form in a table. I want the table to only display the rows which have values, but cannot work out how to do this. So far I have just added multiple rows and am using display:none in order to not display them, but I do not cannot think of a way to get the th:text="${name1}" to display.
Here is an example of the way I am doing it so far:
<table id="table">
<tr id="tableRow">
<th class="tableHeader">Name</th>
<th class="tableHeader">Description</th>
</tr>
<tr id="tableRow" style="display:none">
<td class="tableCell" th:text="${name1}"></td>
<td class="tableCell" th:text="${description1}"></td>
</tr>
<tr id="tableRow" style="display:none">
<td class="tableCell" th:text="${name2}"></td>
<td class="tableCell" th:text="${description2}"></td>
</tr>
<tr id="tableRow" style="display:none">
<td class="tableCell" th:text="${name3}"></td>
<td class="tableCell" th:text="${description3}"></td>
</tr>
</table>
I am relatively new to coding and so any help would be appreciated.
you need to test values before consuming it
<table id="table">
<tr id="tableRow">
<th class="tableHeader">Name</th>
<th class="tableHeader">Description</th>
</tr>
<tr id="tableRow" th:if="${name1 != null or description1 != null}">
<td class="tableCell" th:text="${name1}"></td>
<td class="tableCell" th:text="${description1}"></td>
</tr>
<tr id="tableRow" th:if="${name2 != null or description2 != null}">
<td class="tableCell" th:text="${name2}"></td>
<td class="tableCell" th:text="${description2}"></td>
</tr>
<tr id="tableRow" th:if="${name3 != null or description3 != null}">
<td class="tableCell" th:text="${name3}"></td>
<td class="tableCell" th:text="${description3}"></td>
</tr>
</table>
I found a good way to do it using th:each:
<table id="table">
<tr id="tableRow">
<th class="tableHeader">Name</th>
<th class="tableHeader">Description</th>
</tr>
<tr id="tableRow" th:each="inputMap : ${InputMap}">
<td class="tableCell" th:text="${inputMap.value.name}"></td>
<td class="tableCell" th:text="${inputMap.value.description}"></td>
</tr>
</table>
The ${InputMap} comes from my controller:
#GetMapping("/tablePage")
public void getTableData(Model model) {
inputRepository.findAll().forEach(inputObject -> {
inputMap.put(inputObject.id, inputObject);
});
if (inputMap != null){
inputMap.forEach((id, i) -> {
model.addAttribute(id + "name", id + i.getName());
model.addAttribute(id + "description", id + i.getDescription());
});
}
model.addAttribute("InputMap", inputMap);
}

how to send html email in android?

Hi I am making an app in which I am sending an email to a specific address
This email is a html email with table and images and all...
Is I have tried to add Html.fromhtml() but it keeps saying type mismatch
needed string found spanned....
If you need any of my code please comment
Please suggest any tutorial if you have in mind
EDIT
I forgot to mention I am sending mail using javax.maillibrary I am not using Intents
I tried to use Html.tohtml(Spanned text) its giving the message of type mismatch cant convert String to spannedtext
I have no idea whats happening
I am receiving the html data in my mail if i just go with it
UPDATE
I am fetching the content from a string resource
and this is what I am getting as result
$message = ' For Support enquiry#makeintern.comContact Form Enquiry !
Name: :'.$name.'Email: :'.$email.'Contact: :'.$mobile.'Message:
:'.$message.'Date-Time: :'.$current_date.'
Thanks and Regards MakeIntern Team Account Manager - MakeIntern Cell
www.makeintern.com enquiry#makeintern.com
If any query Please call us on : 011-45544188  www.makeintern.com |
enquiry#makeintern.com 
from---
<string name="email">$message = \'<center>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center" bgcolor="#FFFFFF">
<table width="620px" cellpadding="0" cellspacing="0">
<tr>
<td width="400px" bgcolor="#000000" style="color:#FFFFFF; text-
decoration:none; float:left;font-size:10px;margin: -18px 3px -1px 11px; font-weight:bold; padding:2px; text-decoration:none; padding-left:0px;">For Support <span style="text-decoration:none; color:#FFFFFF;">enquiry#makeintern.com</span></td>
<td width="220px" bgcolor="#000000"></td>
</tr>
<tr style="background-color:#737373;">
<td width="290" align="left" valign="middle"><a href="http://makeintern.com" target="_blank"><img src="http://www.makeintern.com/images/makeintern.jpg" width="136" border="0" alt="MakeIntern" style="display:block; padding-left:0px;"></a></td>
<td width="290" align="right" style="text-align:right; font-family:Arial, Segoe UI,Helvetica Neue, Helvetica, sans-serif; font-size:18px; line-height:18px; color:#FFFFFF; font-weight:normal; padding-right:10px;">Contact Form Enquiry !<br>
</td>
</tr>
<tr>
<td height="12px" colspan="2"></td>
</tr>
<tr>
<td colspan="2" align="center" style="line-height:16px; font-family:arial; font-size:12px; color:#888888; text-align:left;">
<table cellspacing="0" cellpadding="0">
<tr>
<td width="200px" style="font-weight:bold;">Name: </td>
<td width="100px">:</td>
<td>\'.$name.\'</td>
</tr>
<tr>
<td width="200px" style="font-weight:bold;">Email: </td>
<td width="100px">:</td>
<td>\'.$email.\'</td>
</tr>
<tr>
<td width="200px" style="font-weight:bold;">Contact: </td>
<td width="100px">:</td>
<td>\'.$mobile.\'</td>
</tr>
<tr>
<td width="200px" style="font-weight:bold;">Message: </td>
<td width="100px">:</td>
<td>\'.$message.\'</td>
</tr>
<tr>
<td width="200px" style="font-weight:bold;">Date-Time: </td>
<td width="100px">:</td>
<td>\'.$current_date.\'</td>
</tr>
</table>
<br/><br/>
Thanks and Regards <br/>
MakeIntern Team <br/>
Account Manager - MakeIntern Cell <br/>
www.makeintern.com<br/>
enquiry#makeintern.com<br/><br/>
<b>If any query Please call us on : 011-45544188</b><br/>
</td>
</tr>
<tr>
<td height="12px"></td>
</tr>
<tr>
<td colspan="2"><img src="http://www.myhotbooking.com/images/email-template/bar.png"></td>
</tr>
<tr>
<td colspan="2" bgcolor="#737373" height="90px">
<table cellpadding="0" cellspacing="0" width="620px">
<tr>
<td height="10px"></td>
</tr>
<tr>
<td align="center" style="color:#FFFFFF;" height="20px"><a href="http://www.makeintern.com/">www.makeintern.com </a>| <span style="color:#FFFFFF; text-decoration:none;">enquiry#makeintern.com</span></td>
</tr>
<tr>
<td align="center" valign="middle">
<a href="https://www.facebook.com/makeinterns" target="_blank"><img src="http://www.myhotbooking.com/images/email-template/icon-facebook.png" width="26" height="26" border="0" alt="Facebook"></a><a href="https://twitter.com/makeintern" target="_blank"><img src="http://www.myhotbooking.com/images/email-template/icon-twitter.png" width="26" height="26" border="0" alt="Twitter"></a><a href="https://www.linkedin.com/company/makeintern" target="_blank"><img src="http://www.myhotbooking.com/images/email-template/icon-linkedin.png" width="26" height="26" border="0" alt="Linkedin"></a><a href="https://plus.google.com/+makeintern" target="_blank"><img src="http://www.myhotbooking.com/images/email-template/icon-google-plus.png" width="26" height="26" border="0" alt="Google+"></a></td>
</tr>
<tr>
<td align="center" style="color:#FFFFFF;"></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>\'</string>
Thankyou in advance
Try Below Code :
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT,getResources().getString(R.string.email_subject));
sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(getResources().getString(R.string.email_text)));
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, ""));
string.xml
<resources>
<string name="email_subject">Download App for your smartphone.</string>
<string name="email_text"><![CDATA[Hey,<br/>I just downloaded App on my Android.<br/>It is a smartphone Manager.This app even lets me book parties,search restaurants.<br/>App is available for Android.<br/>
Get it now from http://www.exampleapp.com/download]]></string>
</resources>

How to select elements using Jsoup

I have table where I want to iterate over rows (tr) in root tbody and not rows in it child
I try this but with no success:
Elements tableRows = table.select("tr");
this get tr also in it child so I have there duplicates
Elements tableRows = table.select("tbody > td:first-child");
this doesnt work too
here is my table:
<table border="0" cellspacing="0" cellpadding="2" width="100%" align="center">
<tbody>
<tr>
<td class="head">Rank</td>
<td class="Head"> </td>
<td class="Lhead">Club</td>
<td class="head">Nation</td>
<td class="head">Rank points</td>
<td class="head">Five best results (by points)</td>
</tr>
<tr>
<td class="playerB">60. (1.)</td>
<td class="Lplayer">Imrich Blasko</td>
<td class="Lplayer">THC Blue Dragon Kosice</td>
<td class="player"><img src="flags/SVK.gif" alt="SVK" /></td>
<td class="playerB">3 398</td>
<td class="Lplayer">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="Lplayer">World Championships 2013</td>
<td class="Rplayer">817</td>
</tr>
<tr>
<td class="Lplayer">Czech Open 2012</td>
<td class="Rplayer">674</td>
</tr>
<tr>
<td class="Lplayer">Czech Open 2013</td>
<td class="Rplayer">668</td>
</tr>
<tr>
<td class="Lplayer">Slovak Championships 2013</td>
<td class="Rplayer">621</td>
</tr>
<tr>
<td class="Lplayer">Bratislava Cup 2013</td>
<td class="Rplayer">617</td>
</tr>
</tbody>
</table></td>
</tr>
<tr>
<td colspan="6">
<hr color="#008080" width="100%" /></td>
</tr>
<tr>
<td class="playerB">159. (2.)</td>
<td class="Lplayer">Tibor Valachovic ml.</td>
<td class="Lplayer">SHK Skalica</td>
<td class="player"><img src="flags/SVK.gif" alt="SVK" /></td>
<td class="playerB">2 847</td>
<td class="Lplayer">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="Lplayer">Czech Open 2013</td>
<td class="Rplayer">639</td>
</tr>
<tr>
<td class="Lplayer">Brno 2013</td>
<td class="Rplayer">594</td>
</tr>
<tr>
<td class="Lplayer">Brno 2014</td>
<td class="Rplayer">583</td>
</tr>
<tr>
<td class="Lplayer">Slovak Championships 2013</td>
<td class="Rplayer">569</td>
</tr>
<tr>
<td class="Lplayer">Czech Open 2011</td>
<td class="Rplayer">461</td>
</tr>
</tbody>
</table></td>
</tr>
<tr>
<td colspan="6">
<hr color="#008080" width="100%" /></td>
</tr>
</tbody>
</table>
Try:
Elements tableRows = table.select(":root > tbody > tr");

Categories