Quarkus Qute not parsing html template correctly - quarkus-qute

I am using quarkus-qute to generate html from a html template file. However, it returns a pure string. For e.g. in the template file, userNotification.html
<table width="600" cellpadding="0" cellspacing="0" border="0" class="table">
<tr>
<td width="600" bgcolor="#f2f2f2" class="logocell">
is parsed as
<table width=\"600\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"table\">\n
<tr>\n
<td width=\"600\" bgcolor=\"#f2f2f2\" class=\"logocell\">\n
The parser escaped the double quotes and added \n to the end of line.
Section of class that parses
#CheckedTemplate(requireTypeSafeExpressions = false)
static class Templates {
static native TemplateInstance userNotification(Email email);
}
.....
.....
private String getTemplateOutput( Message notificationMessage) {
return Templates.userNotification(email).render();
}
Its not a REST API call.
Any suggesstions?

Related

Spring WebFlux+Thymeleaf How to display reactive collection size

I am developing a spring boot service to manage a REST server.
The service displays a reactive list on one of the forms.
It is very simple code.
Table in thymeleaf template
<table>
<thead>
<tr>
<td>ID</td>
<td>Name</td>
<td>Alive</td>
</tr>
</thead>
<tbody>
<tr th:each="item : ${items}">
<td th:text="${item.counterpartID}" />
<td th:text="${item.counterpartName}" />
<td th:text="${item.alive}"/>
</tr>
</tbody>
</table>
Controller
#GetMapping("/counterparties")
public String init(Model model) {
IReactiveDataDriverContextVariable reactiveDataDrivenMode =
new ReactiveDataDriverContextVariable(
webClient
.get()
.uri(uriBuilder -> uriBuilder
.path("/findAllCounterpart")
.build())
.retrieve()
.bodyToFlux(Counterpart.class)
, 1);
model.addAttribute("items", reactiveDataDrivenMode);
return "counterparties.html";
}
Now I want to display collection size (numbers of rows in table).
I added to the html temlate tag
<label th:text="'total rows: ' + ${#lists.size(items)}">rows number in table</label>
And I got an unexpected result
total rows: 1
How to display the real number of rows in a reactive collection ?
Thanks.
I decided to use javascript.
<script language="JavaScript">
function countLoadedRows() {
var table = document.getElementById('tableId');
var tbodyRowCount = table.tBodies[0].rows.length;
console.log('total rows: ' + tbodyRowCount);
document.getElementById('totalRowsId').textContent = tbodyRowCount
}
document.addEventListener('readystatechange', countLoadedRows)
</script>
and html tags is
<input type = "button" onclick = "countLoadedRows()" value = "Total rows: "><label id="totalRowsId">???</label>
<table id="tableId">
...
</table>

How to retrieve the text from an outer element using selenium webdriver?

How to retrieve the text 'caught jake' from the below code using selenium webdriver?
Am able to point to that text using the below xpath but am unable to print the text. :(
//*[#id='full-scorecard']/div[2]/div/table[1]/tbody/tr[3]/td[2]/child::text()
<div class="row">
<div class="large 20 columns">
<table class="batting-table innings" width="100%">
<tbody>
<tr class="tr-heading">
<tr>
<tr class="dismissal-detail" style="display: table-row;">
<td width="2%" />
<td colspan="8">
<b>12.6</b> caught Jake
<b>73/4</b>
<br/>
Using java you can retrieve from following lines:
String text = driver.findElement(By.xpath("//div[#class='large 20 columns']")).getText();
System.Out.print("Text= "+text);
Above line will return all inner tags string's of div element.
If you want to get only 12.6 text, then use below lines:
String text = driver.findElement(By.xpath("//table[#class='batting-table innings']/tr/tr/tr/td[2]/b")).getText();
System.Out.print("Text= "+text);
And be sure that there should be single element which has this xpath 'By.xpath("//table[#class='batting-table innings']/tr/tr/tr/td[2]/b")', otherwise you will get an exception.
depend on your language, you can use following xpath expression:
//div[#class='large 20 columns']/table/tbody/tr/tr/td[2]/child::text()
full Java code:
JavascriptExecutor js = (JavascriptExecutor) driver;
String jsx = "return document.evaluate(\"//*[#id='full-scorecard']/div[2]/div/table[1]/tbody/tr[3]/td[2]/child::text()\", document, null, XPathResult.STRING_TYPE, null).stringValue;";
String objList = js.executeScript(jsx);
System.out.println( (String) objList);

how to create cart content as pdf output in PRESTASHOP

I have to print the cart content in a pdf file and download.
I have try some code using pdfinvoicecontroller.php
I have created new controller - controllers/front/CartprintController.php
class CartprintControllerCore extends FrontController
{
protected $display_header = false;
protected $display_footer = false;
public $content_only = true;
protected $template;
public $filename;
public function postProcess()
{
if (!$this->context->customer->isLogged() && !Tools::getValue('secure_key'))
Tools::redirect('index.php?controller=authentication&back=cartprint');
}
public function display()
{
$displayproducts = $this->context->cart->getProducts();
$pdf = new PDF($displayproducts, PDF::TEMPLATE_INVOICE_CART, $this->context->smarty, $this->context->language->id);
$pdf->render();
}
public function getTemplate()
{
$template = _PS_THEME_PDF_DIR_.'/cartprint.tpl';
return $template;
}
}
Added
const TEMPLATE_INVOICE_CART = 'Cartprint';
line in classes/pdf/PDF.php
3.then created a HTML template file in pdf/cartprint.tpl
<table id="cart_summary" class="std">
<thead>
<tr>
<th class="cart_product first_item">{l s='Product'}</th>
<th class="cart_description item">{l s='Description'}</th>
<th class="cart_unit item">{l s='Unit price'}</th>
<th class="cart_quantity item">{l s='Qty'}</th>
<th class="cart_total item">{l s='Total'}</th>
</tr>
</thead>
{foreach $displayproducts item=prodpef name=prodpef }
<tr>
<td class="cart_product first_item">{$prodpef.name}</td>
<td class="cart_description item">{$prodpef.description_short}</td>
<td class="cart_unit item">{$prodpef.price}</td>>
<td class="cart_quantity item">{$prodpef.cart_quantity}</td>>
<td class="cart_total item">{$prodpef.total}</td>>
</tr>
{/foreach}
</table>
4.in shopping cart page i have created a link
<img src="{$img_dir}icon/pdf.gif" alt="{l s='Invoice'}" class="icon" />
but still i am not getting pdf output .
Any help ?
First it will be better to override PDF class and second you need to create a HTMLTemplateCartPrint.php file in classes dir or override classes dir in order to generate pdf file.
Best regards.

How to handle Html tags in string - when displayed in MVC page

So I'm retrieving data from the Rally web service and the description field contains html tags.
My MVC page looks like this:
<table width="100%" id="stories">
<tr>
<td>ID</td>
<td>Name</td>
<td>Description</td>
<td>TaskEstimateTotal</td>
</tr>
#foreach (var story in Model.UserStories)
{
<tr>
<td>#story["FormattedID"]</td>
<td>#story["Name"]</td>
<td>#story["Description"]</td>
<td>#story["TaskEstimateTotal"]</td>
</tr>
}
</table>
The html tags appear as text
eg:
<DIV>As a Marketing Analytics And Data Manager</DIV>
I've tried encoding and decoding it but neither of those are producing the desired response. Encoding it will convert the < into < type text.
<td>#HttpUtility.HtmlEncode(story["Description"])</td>
Hopefully it's just something simple I've missed!
Unless I should be stripping out the tags?
Have you tried:
<td>#Html.Raw(story["Description"])</td>
MSDN: http://msdn.microsoft.com/en-us/library/gg480740(v=vs.98).aspx
You can do:
<td>#Html.Raw(story["Description"])</td>
Razor html encodes strings by default.

code behind in newform.Aspx?

I have a list that must be filled with a bit of code behind (prepopulating some fields, and do a bit of work on the save button.)
What is the best way to do that ?
thx
Edit: I ended by creating a custom webpart on the default.aspx. In this web part I have a bunch of :
<table border="0" cellspacing="0" width="100%">
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<h3 class="ms-standardheader">
<nobr>Title<span class="ms-formvalidation"> *</span>
</nobr>
</h3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="fldTitle" ControlMode="New" FieldName="Title" ListId="{MyListID}" />
<SharePoint:FieldDescription runat="server" id="ff1description" FieldName="Title" ControlMode="New" ListId="{MyListID}"/>
</td>
</tr>
This is working, but I found this in a bit painfull because I have to read each form field in code behind :
private void Set(SPListItem item, string fieldInternalName, object fieldValue)
{
var field = item.Fields.GetFieldByInternalName(fieldInternalName);
item[fieldInternalName] = fieldValue;
}
protected void Btn_Ok_Click(object sender, EventArgs e)
{
SPWeb thisWeb = SPContext.Current.Web;
SPList myList= thisWeb.Lists["mylist"];
SPListItem newItem;
newItem= myList.Items.Add();
var router = thisWeb.EnsureUser(#"myuser");
Set(newItem, "Title", fldTitle.Value);
Set(newItem, "OtherField", fldOther.Value);
Set(newItem, "AnotherField", GetFromBusinessLogic());
SPUtility.Redirect(thisWeb.Url, SPRedirectFlags.Default, System.Web.HttpContext.Current);
newItem.Update();
}
Is there any way to wrap all of this in a custom form container ? Maybe a custom ListFormWebPart with inner templates and code-behind events ?
You can follow the suggestion here to add in the code-behind.
BUT even if you put in a code-behind file, you still cannot reference the controls (fields, save buttons etc) on the form from the code-behind.
I would suggest writing up a web service (asmx or WCF) and host it on the Sharepoint instance.
You can then use javascript and AJAX calls to perform initialization and validation.