i have a Thymeleaf template for email, and I am trying to pass two parameters to create an URL.
The part I am talking about looks like this:
<p><span>To accept the protocol click <a th:href="#{http://localhost:8080/accept/(invoiceId=${invoiceId}),(contractorEmail=${email})">HERE</a></span></p>
When I run the function that should create and send an email, I get:
Could not parse as expression: "#{http://localhost:8080/accept/(invoiceId=${invoiceId}),(contractorEmail=${email})" (template: "mailTemplate" - line 7, col 47)
How can I pass both parameters to the URL?
This is all documented in Thymeleaf's Standard URL Syntax.
#{http://localhost:8080/accept/(invoiceId=${invoiceId},contractorEmail=${email})}
Related
I'm trying to get Thymeleaf to build me a URL where the domain part is a parameter, some fragment is a literal string, and the query parameters are also parameterized.
The documentation offers some examples:
#{${myDomain}/literalUrl}
#{${myDomain}'/literalUrl'}
#{/literalUrl(query=${queryValue})}
#{'/literalUrl'(query=${queryValue})}
#{${myDomain}(query=${queryValue})}
or even
<a th:with="baseUrl=${myDomain}" th:href="#{${baseUrl}}(query=${queryValue})}">
Separately, all of these work well. But if I try to combine them, the domain part suddenly refuses to resolve:
#{${myDomain}/literalUrl(query=${queryValue})} and #{${myDomain}+'/literalUrl'+(query=${queryValue})} each resolve to ${myDomain}/literalUrl?query=queryValue, and
How do I get Thymeleaf to properly generate my url https://example.com/literalUrl?query=queryValue
Don't know if this is a legit solution for your problem, but if you concat the literalUrl with the first parameter, it will work. Down side: you need an additional model parameter.
<a th:href="#{${linkData+path}(q=${queryParam})}">some link</a>
gets
some link
with model params:
mv.addObject("linkData", "https://example.com");
mv.addObject("path", "/literalUrl");
mv.addObject("queryParam", "queryValue");
I sent one request as URL with data to servlet, But by default servlet is modifying the data and sending as request. Can you please suggest how to maintain the request URL with data which i passed to servlet should remain same ?
Example:- when i am passing the data to servlet
http://localhost/helloservlet/servlet/ppd.abcd.build.coupons.CouponValueFormatterServlet?dsn=frd_abc_abcde&lang=ENG&val=PRCTXT|12345 &ABCDEFG
when it using the above url in servelt as request , like string abc = request.getParameter("val"), the val attribute is trimmed automatically and assigned as " val=PRCTXT|12345" but it supposed to be like " val = PRCTXT|12345 &ABCDEFG ". Please help me on this.
The servlet interprets each & in the URL as the start of a new parameter. So when it sees &ABCDEFG, it thinks you are sending a new parameter called ABCDEFG with no value (though this is technically a "keyless value" according to the specifications).
Two things to fix this, first is when you want to actually send an &, use %26 instead. This will be skipped by the code that divides up the parameters, but converted to a real & in the parameter's value.
Second is to replace spaces with +. Spaces in URLs work sometimes but can be problematic.
So your actual request URL should look like this:
http://localhost/helloservlet/servlet/ppd.abcd.build.coupons.CouponValueFormatterServlet?dsn=frd_abc_abcde&lang=ENG&val=PRCTXT|12345+%26ABCDEFG
If you're building these parameters in javascript, you can use encodeURIComponent() to fix all problem characters for you. So you could do something like this:
var userInput = *get some input here*
var addr = 'http://www.example.com?param1=' + encodeURIComponent(userInput);
I'm working on a task that's using Velocity to generate an email from a template. One of my requirements is that the email message be localized, based on a Locale submitted by the user. I've got this working for the most part, using Velocity's ResourceTool to pull in a MessageBundle. The other requirement is that I can only have one template - I don't want one template per language or locale because this is difficult to maintain if changes are needed.
As a part of a MessageBundle, I can have what's referred to as "compound messages", which are messages that have variables that are replaced when the message is evaluated. For example:
dear.name=Dear {0}:
My question is this: how do I get Velocity to replace the {0} value with a name that I pass in?
It's not acceptable to simply modify my Velocity template so that I simply replace the name at the template level - in some languages, the greeting word "Dear" comes after the name, so this would yield an incorrect output.
Found the answer: in my velocity template, I can use the Velocity directive:
#evaluate(${msg.dear.name})
And in my message bundle, my message looks like:
dear.name=Dear $name
If I set the name in the Velocity context, it gets replaced as I expect.
I want to send a string to a function defined in jsp taglib. Specifically, I want to send a param that I'm getting in the page.
i.e. Here the second parameter should be a string. If I use ${param.username} it gives an error, probably because ${param.username} is an object and not a string
${insert:insert(5,)}
You can't embed an EL expression (${...}) inside another EL expression (${...}). You just need
${insert:insert(5, param.username)}
I am using StringTemplate v4.05 to build my web application.
As I am using STRawGroupDir, I do not define something like init(v) :: ... in each .st
Currently I can successfully render the sub-template like below:
('$' is my delimiter )
$/elements/test()$
But when test.st is like below
<div>Hello $name$</div>
I do not know how to pass the argument to $name$.
My target is like below
$/elements/test(["Cavid"])$
$/elements/test(["Daniel"])$
$/elements/test(["Candy"])$
When using STRawGroupDir and template has only one placeholder, it can be referred to as it.
In your case test.st would be
<div>Hello $it$</div>