show english numbers inside an localized ( to arabic) tymleaf view - java

I have a html view in my spring mvc app, and I localized it to arabic but I need English number instead arabic number inside my view how can I achieve it?
I already tried this for date fields but it doesn't work:
<tr th:if="${#environment.getProperty('snapp.box.default.language').matches('ar')}">
<td th:text="#{snapp.box.middleman.invoice.create.date}"></td>
<td class="date"
th:text="${T(org.thymeleaf.util.DateUtils).format(createdAt,'yyyy/MM/dd HH:mm', #locale.forLanguageTag('en'))}"></td>
</tr>

Related

How to resolve an ArrayIndexOutOfBoundsException in Netsuite Advanced PDF Template

I'm working on a template that will group results from a saved search building on these very helpful stackoverflow posts:
How to remove duplicate elements in a array using freemarker?
How can I group a list in an advanced pdf/html sheet in netsuite/freemarker?
The template I've created works fine for me, but when a different user tries to print with it they get an "unexpected error" from Netsuite, and when I logged into that user's account and tried to open the template and save it, I got this error:
The template cannot be saved due to the following errors:
Exception during template merging.com.netledger.templates.TemplateServiceException: Exception during template merging.java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 10
This other user has the same Netsuite admin role I do, and is using the same browser (Firefox). I even logged into her Netsuite account on my computer in Firefox and replicated the error, so it seems tied to her NS account(?).
My template is meant to simply group and add page breaks to the results of a saved search that returns salesperson commissions per transaction. Here is the code:
<body padding="0.5in 0.5in 0.5in 0.5in" size="Letter-landscape">
<#assign entitygroup = []>
<#list results as group><!--if the saved search results weren't sorted, they should have been be sorted here-->
<#assign groupID = group.formulatext> <!--"formulatext" is the sales rep or partner or dept, from the saved search-->
<#if entitygroup?seq_contains(groupID)><!-- do nothing / don't add it to the sequence-->
<#else><#assign entitygroup = entitygroup + [groupID]><!--add this entity to the sequence so it will be skipped next time -->
<table>
<tr><td colspan="9" style="font-weight:bold; font-size:12px;">${group.formulatext}</td></tr>
<tr>
<th style="width:10%;">${group.tranid#label}</th>
<th style="width:10%;">${group.trandate#label}</th>
<th style="width:10%;">${group.closedate#label}</th>
<th style="width:20%;">${group.companyname#label}</th>
<th align="right" style="width:10%;">${group.netamountnotax#label}</th>
<th align="right" style="width:10%;">${group.totalcostestimate#label}</th>
<th align="right" style="width:10%;">${group.tranestgrossprofit#label}</th>
<th align="right" style="width:10%;">${group.formulapercent#label}</th>
<th align="right" style="width:10%;">${group.formulacurrency#label}</th>
</tr>
<#assign total_tot = 0>
<#assign total_cost = 0>
<#assign total_profit = 0>
<#assign total_comm = 0>
<#list results as result>
<#if result.formulatext == groupID><!-- if the "entity" (rep, partner, dep) matches the current group-->
<tr>
<td style="width:10%;">${result.tranid}</td>
<td style="width:10%;">${result.trandate}</td>
<td style="width:10%;">${result.closedate}</td>
<td style="width:20%;">${result.companyname}</td>
<td align="right" style="width:10%;">${result.netamountnotax}</td>
<td align="right" style="width:10%;">${result.totalcostestimate}</td>
<td align="right" style="width:10%;">${result.tranestgrossprofit}</td>
<td align="right" style="width:10%;">${result.formulapercent}</td>
<td align="right" style="width:10%;">${result.formulacurrency}</td>
</tr>
<#assign total_tot = total_tot + result.netamountnotax>
<#assign total_cost = total_cost + result.totalcostestimate>
<#assign total_profit = total_profit + result.tranestgrossprofit>
<#assign total_comm = total_comm + result.formulacurrency>
</#if><!-- if the "entity" (rep, partner, dep) matches the current group-->
</#list><!--loop for the lines data-->
<tr style="font-weight:bold;">
<td> </td>
<td> </td>
<td> </td>
<td align="right"><strong>Totals:</strong></td>
<td align="right">${total_tot}</td>
<td align="right">${total_cost}</td>
<td align="right">${total_profit}</td>
<td> </td>
<td align="right">${total_comm}</td>
</tr>
</table>
<pbr />
</#if>
</#list><!-- loop for the "entity" grouping / goes back up to assign the next group-->
</body>
Any help is greatly appreciated, including taking a different approach to this problem!
[Additional info after more testing:]
As I've tried to run this down it seems that the way I'm doing my comments might have something to do with the out of bounds error, perhaps causing the template editor to think I've left out something so the query on the array had no results?
Logged in as the other admin user I deleted the entire body of my template, saved, then re-added it, and the error did not reoccur. Maybe the template engine reinterpreted my comments correctly (or as I intended)?
I've run into this error on another template now and re-did all of my comments in the freemarker way ("<#--") and again it stopped throwing the error, so that's a little more conclusive.
I hope this is helpful to somebody. I'm still working on these templates, so I'll update here if I get a more definitive answer.
Your error is likely because you are trying to save your template as an email template of some sort but are using N/render.TemplateRenderer and not N/render.mergeEmail.
I just store my custom templates as files to avoid validation errors on save.
Prior to saving I use https://try.freemarker.apache.org/ where running the template takes some time.
Unexpected errors generally mean a syntax error or some data that you are expecting isn't there. You might try logging your non-record data sources or have the user who is seeing the error try running your saved search directly to see if the UI reports issues accessing the data.
After working with this and another complex template I feel pretty confident that the inconsistent behavior I noted in my question was caused by using the wrong commenting tags: <!-- instead of <#--. Netsuite's template editor encourages the html-style comment by putting the text in a consistent brownish color (when using freemarker comments the text colors seem to ignore the comment tag completely) so it's a bit misleading. At least for my templates changing all the comments to the <#-- tag saved the day.

How can I add hyperlinks to columns of a table using thymeleaf th:each?

I'm trying to create hyperlinks for each element in a table generated by thymeleaf.
<tbody>
<tr th:each="author :${authors}">
<td th:text="${author.id}"></td>
<a th:href="#{/authors/{id}(id=${author.id})}">
<td class="authorLink" th:text="${author.firstName}"></td>
</a>
<td th:text="${author.lastName}"></td>
</tr>
</tbody>
The code above is giving me an output of the generated hyperlinks outside of the table.
This is a link to the generated html.
https://i.gyazo.com/7dae68eb42cd084b59030e7b17590e5e.png
"linklinklinklink" is the output of the generated hyperlinks. I would like for the 'First Name' column to become hyperlinks.
If anyone can tell me how I can accomplish this that would be great.
Place your <a> tag inside the <td> cell where you want the link to appear:
<td>
<a th:href="#{/authors/{id}(id=${author.id})}"
th:text="${author.id}"></a>
</td>
Note how you can use a th:text="..." attribute inside the <a> tag, as well, to control the visible text for the link.
In your case, you had a <a> tag inside a row, but not part of any cell. This is invalid HTML, so your browser's HTML renderer dumped the links somewhere else (above the table, in this case).

Get data of html table from a website in android using Jsoup library,

I am working on an app where I am parsing some data from one or two websites. Luckily I did it for some of my targeted data but not. Now that I am using Jsoup for parsing the data from a website I used same jsoup format to get data of phase 2 as I did for phase 1 of my app but this time nothing is fetching arraylist showing up blank. I checked both HTML codes and there is a bit of difference in both.
In my phase1 i parsed the table using it's class and then i get the respective of that table. In the 2nd phase, the format of table and its tr & tds are different so i am struggling to figure it out. I am posting the html code from which i want to get data.
<div class="view-content">
<table class="views-table cols-3">
<thead>
</thead>
<tbody>
<tr class="odd views-row-first views-row-last">
<td class="views-field views-field-counter">
1 </td>
<td class="views-field views-field-body">
<p>some text here</p>
</td>
<td class="views-field views-field-field-notif-pdf">
Size :- 1.85 MB, Language:- English</td>
</tr>
</tbody>
</table>
</div>
I want the data inside above table tag and i am having problems to figure it out how it will be done with all classes in tr and td. Any help or suggestion will be highly appreciated..
THANK YOU!
You can use selectors in Jsoup:
File input = new File("path_to_html/test.html");
Document doc = Jsoup.parse(input, StandardCharsets.UTF_8.name());
///select table body
Element tbody = doc.select("tbody").first();
other examples at:
https://jsoup.org/cookbook/extracting-data/selector-syntax

How to use foreach in Velocity template for Table

I have an object invoice, it has some list of Invoice Items. Now I want to get print of my invoices. For that I used Velocity Template. But my model template not getting my required format.
I used this .
I got this Output
For below template
I got this Output
But I want like this
Guys Plz help me to get requried format
Try the following code
<table>
<tr>
<th>Name</th>
<th>Desp</th>
<th>Qty></th>
<td>Unit Price</th>
<th>Disc</th>
<th>Total</th>
<th>vat rate</th>
<th>vat amount</th>
</tr>
#foreach ($titem in $!invoice.transactionItems)
<tr>
<td>$!titem.item.name</td>
<td>$!titem.description</td>
<td>$!titem.quantity</td>
<td>$!titem.unitPrice</td>
.....
</tr>
#end
</table>
Firstly,you need to write some html code as well as css,once have the html template, you can fill your object value to the html code, as your format, you need to make use of the html table label to present your result.

How to iterate over <td> tags with condition using jsoup

I am able get all text with in tags but I want to access only specific td tags.
Eg.I want to get data of second cell text whose first cell html contains attribute
a name="manufacturer"
or Content.I am using Jsoup.
<tabel>
<tr>
<td><a name="Manufacturer"></a>manufacturer</td>
<td>happiness</td>
</tr>
<td>manuf</td>
<td>hap</td>
</tr>
<tr>
<td>tents</td>
<td>acd</td>
</tr>
<tr>
<td><a name="Content"></a>Contents</td>
<td>abcd</td>
</tr>
</tabel>
I am using the code ..
doc.select("a[name=Manufacturer]");
..but its giving me the reference of cell one ,I need to go to cell two get cell two text
You need to use selector like [attr=value]: elements with attribute value, e.g. [width=500].
Take a look at official documentation Selector Syntax

Categories