Mustache is throwing an error about the null value - kotlin

I have a following Kotlin object type with default null value for a field:
data class Field(
val content: String? = null,
val field: String = ""
)
Then I try to pass the object:
val myObject = Field(field = "something")
to the mustache template:
<!DOCTYPE ...>
<html>
<head>
<meta .../>
</head>
<body ...">
{{#myObject}}
{{#content}}
{{.}}<br/>
{{/content}}
{{#field}}
{{.}}<br/>
{{/field}}
{{/myObject}}
</body>
</html>
And after filling the template I receive an exception: No key, method or field with name 'content' on line ...
I cannot get what can be wrong

may be you should define the "" for the content default for the problem?

Related

Vue 3 "v-model" with checkboxes but the data is "1" or "0" not "true" or "false"

Because of some reason on the backend, they use 0 or 1 and not false or true for booleans.
So, when I try to use the boolean data from API, TS complains:
// settings.crawl_on outputs 0 or 1
<input
v-model=“settings.crawl_on”
type="checkbox"
/>
I tried adding the below code it doesn't work either:
true-value="1"
false-value="0"
TS says:
(property) InputHTMLAttributes.checked?: any[] | Set | Booleanish
Type 'number' is not assignable to type 'any[] | Set |
Booleanish'.ts(2322)runtime-dom.d.ts(629, 3): The expected type comes from property 'checked' which is declared here on type
'ElementAttrs'
Is there a way to override this or what is the correct use?
Upgraded from Vue 2 to Vue 3, got same issue. This didn't work:
true-value="1"
false-value="0"
But this works:
:true-value="1"
:false-value="0"
For input type="checkbox", 0 will be same as false and 1 will be same as true.
Hence, settings.crawl_on = 1 will be same as settings.crawl_on = true.
I checked same with TypeScript as well as JavaScript and it's working fine in both the languages.
Demo :
new Vue({
el: '#app',
data: {
settings: {
crawl_on: 1
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<input
v-model="settings.crawl_on"
type="checkbox"
/>
</div>
Because static html attributes values are 'String' type. And you are expecting 'Integers'.
So, when you use "v-bind:" making attributes dynamic values, you are sending 'Integers'
true-value="1" <-- string
true-value="1" <-- integer
:true-value="'1'" <-- string

inverse result of query_to_xml() PostgreSQL?

I am using a servlet(servlet1) via a GET method from httpurlconnection() function in order to get the XML generated by an another servlet(servlet2) connected to a postgreSQL Database.
The XML generated by the servlet2 via the statement:
select query_to_xml('select * from test', true, false, '');
I initialize an httpurlconnection() from servlet1 to servlet2 and I stored in a string "response1" the output like that:
String inputLine;
StringBuffer response1 = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response1.append(inputLine);
}
in.close();
//The output in console
System.out.println(response1.toString());
The XML is stored in the string "response1" as:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link type="text/css" rel="stylesheet" href="/pro/inc/form.css;jsessionid=D965FA3338EC4E88F6F7AA0B64308446" />
</head>
<body>
<p><alltests_00_with_defects xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<row>
<n5>a</n5>
<n4>b</n4>
<n3>c</n3>
<n2>d</n2>
<n1>e</n1>
<row>
<row>
<n5>a</n5>
<n4>b</n4>
<n3>c</n3>
<n2>d</n2>
<n1>e</n1>
<row>
</html>
Until here, it's cool!!
Now, I am looking for a solution that can convert BACK the XML generated to data values.
Any ideas?

Dreamweaver ASP command INSERT INTO not passing value

Hi I am trying to create an INSERT INTO script in Dreamweaver Command and ASP.
If I use a static value it works fine, but when I try to declare a variable I get the following error message
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Sybase][ODBC Driver][Adaptive Server Anywhere]Primary key for table 'testing'
is not unique
/coding/Untitled-3.asp, line 30
Now the reason it is telling me the primary key is not unique is it is passing a null value, rather than the value of my field. Code below;
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim Command1__product
Command1__product = Request.Form("product")
%>
<!--#include file="Connections/Conn_PSCRM_Demo.asp" -->
<%
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
If condition = "" Then
MM_IIf = ifFalse
Else
MM_IIf = ifTrue
End If
End Function
%>
<%
Set Command1 = Server.CreateObject ("ADODB.Command")
Command1.ActiveConnection = MM_Conn_PSCRM_Demo_STRING
Command1.CommandText = "INSERT INTO testing (prodref) VALUES (?)"
Command1.Parameters.Append Command1.CreateParameter("product", 201, 1, 25, MM_IIF(Request.Form("Field1") , Request.Form("Field1") , Command1__product & ""))
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post" name="form" id="form">
<label for="Field1"></label>
<input name="Field1" type="text" id="Field1" value="33399">
</form>
</body>
</html>
According to my comment - you'll have to check if your form has been posted or your site has just been initially loaded. In your question the code will be executed everytime the site has been loaded - that's why it works when you provide hardcoded values.
Anything like this code will do the trick
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
If Request.Form("SUBMITBUTTON") <> "" then
Dim Command1__product
Command1__product = Request.Form("product")
' all your code goes here!
%>
Bit of a rookie error, I wasn't declaring the form variable.
I have added a Bindings Request.Form and all is working.

Regarding computed values in extjs

Consider the following piece of code :
<script type="text/javascript" src="/<Computed Value>/samples/home.js"></script>
In the above example, how does 'Computed Value' get populated. I mean what is the general way of doing it in extjs?.
Thanks in advance.
Take a look at the Ext.String.format function: http://docs-origin.sencha.com/extjs/4.1.3/#!/api/Ext.String-method-format. It should do what you need:
var cls = 'my-class',
text = 'Some text';
var s = Ext.String.format('<div class="{0}">{1}</div>', cls, text);
// s now contains the string: '<div class="my-class">Some text</div>'

grails renderpdf plugin, how does it work?

i´m trying to render PDF with renderpdf grails plugin,
but their documentation is very short.
i made a button in my gsp view/file
<button type="button">PDF Me!</button>
and
ByteArrayOutputStream bytes = pdfRenderingService.render(template: "/pdfs/report", model: [data: data])
in a view for binding images
<rendering:inlinePng bytes="${imageBytes}" class="some-class" />
model data is domainInstance and how do i connect the button with this renderpdf?
may be i should more specify my code
def invoice ={
def vermittlungInstance = Vermittlung.get(params.id)
def aa = vermittlungInstance.lieferungen.id
def lieferungInstance = Lieferung.get(aa)
def bb = lieferungInstance.packete.id // .id
def packetInstance = Packet.findAllByIdInList(bb)
if (!vermittlungInstance & !lieferungInstance) {
flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'vermittlung.label', default: 'Vermittlung'), params.id])}"
redirect(action: "list")
}
else {
if(vermittlungInstance.rechnungen.id!=null || vermittlungInstance.lieferungen.id!=null || lieferungInstance.packete.id!=null ){
def a = vermittlungInstance.rechnungen.id
def rechnungList = Rechnung.findById(a)
def b = vermittlungInstance.lieferungen.id
def lieferungList = Lieferung.findById(b)
def c = lieferungInstance.packete.id
//println c
def packetList = Packet.findAllByIdInList(c)//findById(c)
def d = packetInstance.artikel.id//id
def artikelList = Artikel.findAllByIdInList(d)//findById(d)
def e = lieferungInstance.adressen.id
def adresseList = Adresse.findById(e)
[vermittlungInstance: vermittlungInstance,
rechnungInstanceList:rechnungList,
lieferungInstanceList:lieferungList,
packetInstanceList: packetList,
artikelInstanceList: artikelList,
adresseInstanceList: adresseList
]
//System.out.println(c)
}
else{
def rechnungList = Rechnung.all
def lieferungList = Lieferung.all
def packetList = Packet.all
def artikelList = Artikel.all
def adresseList = Adresse.all
[vermittlungInstance: vermittlungInstance,
rechnungInstanceList:rechnungList,
lieferungInstanceList:lieferungList,
packetInstanceList: packetList,
artikelInstanceList: artikelList,
adresseInstanceList: adresseList
]
}
}
}
this is my def in a controller, i tried to put this renderpdf on many places, but it won't render the page, actually i am changing some values in html (browser), so it should render in html.
the controller seems to be a wrong place to renderpdf than, but there is no render function for .gsp
thanks
Add a new action which generates the pdf version of your invoice and link them from your view.
Here is your link:
<g:link action="downloadInvoice" id="${yourInvoiceID}">Download invoice</g:link>
In your controlle add following:
def downloadInvoice = {
def invoice = Invoice.get(params.id) //replace with your logic
renderPdf(template: '/templates/pdf/invoice', model: [invoice: invoice], filename: "yourTitle")
}
Your invoice template is a simple gsp view where you could place all your HTML (including images) and CSS:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Invoice</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="${resource(dir:'css',file:'your.css')}" />
</head>
<body>
<img src="${resource(dir:'images',file:'invoiceLogo.png')}" />
<h1>Invoice: ${invoice.id}</h1>
.
.
.
</body>
</html>
Hope that example helps!
How to add unicode fonts to this plugin ?? unicode characters are not displayed in rendered pdf. The generated pdf contains blank spaces in place of unicode characters, although they are displayed in other gsp pages. later that i tried the below css. but not worked.
#font-face {
font-family: 'Ubuntu';
font-style: normal;
font-weight: 400;
src:url(http://themes.googleusercontent.com/static/fonts/ubuntu/v4/_xyN3apAT_yRRDeqB3sPRg.woff) format('woff');
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: UTF-8;
}
body pre{
font-size: 14px;
font-family: 'Ubuntu', Helvetica, Arial, sans-serif;
}
Thank you,