Thymeleaf replacing property variable with value from server side - thymeleaf

I am trying to make UI by using Thymeleaf template engine. I have a property file, which contains list of messages for validations.
For example: I have a propery customer.collateral.allocated_amount=Entered amount is bigger than your available balance. Balance: {0}
Now this I wanna replace this {0} with value, which I get from server side from database. For example, I query from database and I get 500.50. And what I want to do now, is to display this propery with value. In this example, it would be: Entered amount is bigger than your available balance. Balance: 500.50
I tried to do this, but no luck:
<th class="right" th:inline="text">([[#customer.collateral.allocated_amount]], ${availableAmount})</th>
How could I do this?

Here are the steps you need to follow for a basic set-up to use Thymeleaf messages:
1) Let's assume you have a Thymeleaf template called customers.html.
2) Your properties file must therefore be called customers.properties, and it must be placed in the same directory as the customers.html template.
3) Let's assume your properties file contains this entry:
amountBiggerThanAvailable=Entered amount is bigger than your available balance. Balance: {0}
4) For the placeholder {0} I will assume you have a Java object called account which has a property called availableAmount and which you pass to Thymeleaf in the usual way (i.e. the same way you pass any other data to your Thymeleaf template). Of course, your version may be different.
Here, I will use a <div> for my example - but you can use whatever you want, of course:
5) Use the message in your template like this:
<div th:text="#{customers.amountBiggerThanAvailable(${account.availableAmount})}"></div>
Note that there is no actual content in the div (between the opening <div> and the closing </div>). All the Thymeleaf directives are attributes inside the opening <div>.
The above fragment will generate the following HTML in your web page:
<div>Entered amount is bigger than your available balance. Balance: 123.45</div>
Once you have got this far, there are various enhancement you can make. For example, you can also look into providing localized (translated) messages as described here.

Related

How do you print different templates in netsuite?

I am trying to find the correct template and id to use for a hotprint of an advanced pdf template of an Item Fulfillment.
The hot print url is (with the id bolded) https://system.na3.netsuite.com/app/accounting/print/hotprint.nl?regular=T&sethotprinter=T&id=7600&label=Packing%20Slip&printtype=packingslip&trantype=itemship&orgtrantype=TrnfrOrd&auxtrans=7605
For some reason only certain id=# seems to affect the outcome and the ids I have got to work for two different templates don't match the Custom Transaction Forms ID or the Advanced pdf script id. (example most ids=template 1, while 168,4954, and seemingly random other ids=template 2) I am very confused on how netsuite resolves the hot print url as it normally doesn't include the template= part though I have seen others use it for invoice print urls.
The parameters at the end of the url (the stuff after the ?) are used by Netsuite to control settings used by the webpage which prints the PDFs for you.
In this case, &id=##### refers to the internal id of the document you are printing. You can see this by going to the document, right clicking, selecting inspect, and typing nlapiGetRecordId() into the console. When you click Print, you should see that same number after &id=#####.
&template=### refers to the template you are printing. If you go to Customization -> Forms -> Advanced PDF/HTML Templates, you'll notice a Script ID field in the table. If you substitute the correct Script ID in for the number in &template=###, you'll notice you generate the same PDF. This Script ID acts the same as the number that was previously there.
The reason you're seeing unusual results when you change those numbers is because you're mismatching a record with a template not built for it. So it won't print exactly right, but will sometimes execute anyways.
Anyways, this sort of parameter scheme is a similar scheme to how Suitelets and Restlets work, so in the future, you might experience this sort of thing again.
EDIT: For those reading this in the future, please read the comments.
To customize a packing slip and return form:
If you are printing packing slips and need some customization, you can use a custom invoice form when printing packing slips. For example, you can customize an invoice form to hide the fulfilled item tax rate and amount, and the order total. Then, when you print the packing slip using the custom form through mass print, choose the the packing slip shows the customized information.

Can a <name> tag have a #nullValue and still have text inside?

The current implementation of a CCDA generator I'm working on, prints a message on a <name> tag (in header sections, where no <text> is available) when something's name is not found:
<name>No information</name>
I know the right way to express not found information is through the #nullFlavor attribute:
<name nullFlavor="NI" />
But right now there is a component on the application that reads the value on the tag and shows it in a human-readable view of the CCDA document. If I use #nullflavor only, the field that shows such name will be empty, instead of "No information".
In order to avoid changing such component, I was thinking on adding the #nullFlavor attribute but still letting the message there:
<name nullFlavor="NI">No information</name>
I know this is syntactically correct, because I've tested it with the reference validator and it passes. My question is: from a semantic point of view, is it valid?
Yes it's valid. The particular specification in question - the v3 abstract data types, simple says:
invariant(ST x) where x.nonNull {
x.headCharacter.notEmpty;
};
So if there's no nullFlavor, there must be some content. But the reverse rule is not applied; there can be content if there's a nullFlavor
Although it is not restricted, my point of view is that it is not a good strategy. I understand that you have a restriction regarding this component but, when you are building a CDA, it is important to keep in mind that it is something to be shared with everyone, and I would never expect to find content inside a nullFlavor attributed element.

cumulocity mqtt measurement

I am pretty new to Cumulocity and I am trying to get data into the platform from my own device using mqtt and the smartrest templates. I can get data in using the static templates but they only support certain data types. I am struggling to create the appropriate smartrest template in the UI and the documentation doesn't go into much detail.
I get that the template name goes in the MQTT topic (or selected on login as part of the username) in s/ut/template_name and the messageId of the messages in the template get matched to the first CSV field of the MQTT publish payload. What I don't get is the template terminology. In the UI I choose API->Measurement and Method->POST and I am presented with required values $.type and $.time. My questions:
Is $.type the "measurement fragment type" name or do I have to make it "c8y_CustomMeasurement"? Can I call it whatever I want?
$.time has a value field. Is this the default value if one is not supplied in the publish?
I assume I need to add a numerical value in the optional API values. To link it to the value of the data point should I make the key "c8y_CustomMeasurement.custom.value"?
Am I way off base here?
Every time I publish to my own smartrest template the server drops the connection so I assume its an error in my template setup but I don't see a way of accessing debug messages (also nothing is published back to me on s/e or s/dt).
For the sake of an example, lets say I wish to publish a unitless, timestamped pulse count with payload format "mId,ts,value" with example data "p01,'2017-07-17 12:34:00',1234"
What you wrote so far is mostly correct just to be a bit more precise:
The topic is s/uc/template_id (not the template name, this is just a label)
The $.type refers to the 'type' fragment in the measurement JSON. It is a free text field
In 99% of cases you want to leave the $.time empty. If you set something here it is not the default but fixed to that timestamp and you cannot change it when using the template. If you leave it empty and still not send something in
Example: p01,2017-07-17T12:34:00,1234 (no quotes arounf timestamp and ISO8601 format
Example without sending time: p01,,1234 (sending empty string as time results in server time beeing set. The template is the same)
Hope these points help you to find you issue

Adobe LiveCycle: Changing binding properties of fields at runtime

I have a PDF order form that lists hundreds of product items (inside read only text fields) and they each have an associated "Quantity" field. Is it possible to dynamically change the binding property of the "Quantity" field from "No data binding" to "Use name" based on whether the user has entered a Quantity? I would like to accomplish this to limit the file size of the XML file that gets submitted from the form.
Changing the binding at runtime will not work unless you rerender/reinitialize the form.
You can however use javascript on field exit events or pre-submit event to create XML data elements for quantities. Or use bindings but remove empty xml nodes before submit if you're trying to limit the XML size.
Check out the XFA scripting guide, in particular xfa.datasets.createNode function for creating XML nodes.

Trying to pass an argument/variable into an attribute in Rails

Imagine I have two models for a Greeting Card App: Template and Card. In creating a Card you specify the target's name, age, and which template you want to use (Card belongs_to template). The Template just has say title and body:text attributes.
I would obviously like there to be a placeholder for the target's name (and perhaps age) within the template body, because I want anyone to be able to create a Card, select the template, and see a Card with the chosen template using their target's name. Is there a way to pass in an argument to the body of the Template for the target's name? I have the Card and target info waiting in the controller but I don't know how to pass it the info since in creating the Template the body was typed into a form and is hard coded into the db as an attribute.
The only way around this I see would be to create a view for each Template instead of storing them in the database, or to create several 'chunks' of the template body, and insert the target's name in between. I'd like to figure this out the more efficient way. Thanks in advance!
If you did not want to do this as templates and truly want it store in the db then I would use javascript to replace keys embedded into the text.
This would also offload the search and replace to the client.
I found the easiest way to go about this ended up just using a designated keyword in the attribute and then replacing it in the controller using the ruby method .gsub!

Resources