I cannot use "lt" as query string parameter name in thymeleaf. How can I achieve that?
This is my example code:
<a th:href="#{/payment/otp-resend(lt=${landingToken.sessionId})}" class="sifretekrar" th:text="#{lp.resendOtp}"></a>
And it gives the following error:
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "#{/payment/otp-resend(lt=${landingToken.sessionId})}" (template: "otp-entry-page" - line 70, col 12)
at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:131)
at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:62)
at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:44)
at org.thymeleaf.engine.EngineEventUtils.parseAttributeExpression(EngineEventUtils.java:220)
at org.thymeleaf.engine.EngineEventUtils.computeAttributeExpression(EngineEventUtils.java:207)
at org.thymeleaf.standard.processor.AbstractStandardExpressionAttributeTagProcessor.doProcess(AbstractStandardExpressionAttributeTagProcessor.java:125)
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74)
at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95)
at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633)
at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1314)
at org.thymeleaf.engine.OpenElementTag.beHandled(OpenElementTag.java:205)
at org.thymeleaf.engine.TemplateModel.process(TemplateModel.java:136)
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:661)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072)
at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362)
at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:189)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1370)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1116)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1055)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:998)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:890)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:875)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
Best regards.
EDIT
The accepted answer is correct. However, Intellij IDEA shows it as if it has an error. The screenshot is attached below. The following two lines are working while IDE displays error message for both of them:
<a th:href="#{/payment/mps-otp-resend} + '?lt=' + ${landingToken.sessionId}" class="sifretekrar" th:text="#{lp.resendOtp}"></a>
<a th:href="#{/payment/mps-otp-resend('lt'=${landingToken.sessionId})}" class="sifretekrar" th:text="#{lp.resendOtp}"></a>
You can quote lt, which should allow you to use it as a parameter name:
<a th:href="#{/payment/otp-resend('lt'=${landingToken.sessionId})}" class="sifretekrar" th:text="#{lp.resendOtp}"></a>
Related
i want to add an th:text in select option (Thymeleaf),
<option th:each="case : ${caseCategoryList}" th:value="${case.caseCategoryId}" th:text="${case.caseCategoryName} - ${case.caseCategoryCode}"></option>
but i get this error
08:28:05,501 ERROR [[servlet-context]] Servlet.service() for servlet servlet-context threw exception
org.thymeleaf.exceptions.TemplateProcessingException: Cannot execute subtraction: operands are "INPATIENT" and "IP" (memberrki/member-rki-form:124)
at org.thymeleaf.standard.expression.SubtractionExpression.executeSubtraction(SubtractionExpression.java:91)
at org.thymeleaf.standard.expression.ComplexExpression.executeComplex(ComplexExpression.java:58)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:107)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:133)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:120)
at org.thymeleaf.standard.processor.attr.AbstractStandardTextChildModifierAttrProcessor.getText(AbstractStandardTextChildModifierAttrProcessor.java:68)
at org.thymeleaf.processor.attr.AbstractTextChildModifierAttrProcessor.getModifiedChildren(AbstractTextChildModifierAttrProcessor.java:59)
at org.thymeleaf.processor.attr.AbstractChildrenModifierAttrProcessor.processAttribute(AbstractChildrenModifierAttrProcessor.java:58)
at org.thymeleaf.processor.attr.AbstractAttrProcessor.doProcess(AbstractAttrProcessor.java:87)
at org.thymeleaf.processor.AbstractProcessor.process(AbstractProcessor.java:212)
at org.thymeleaf.dom.Node.applyNextProcessor(Node.java:1016)
at org.thymeleaf.dom.Node.processNode(Node.java:971)
...
can you help me to fix this error,
Using - as suggested by glytching didn't work for me. However, this worked:
th:text="${case.caseCategoryName} + '-' + ${case.caseCategoryCode}"
Thymeleaf is interpreting this: th:text="${case.caseCategoryName} - ${case.caseCategoryCode}" as subtract the value of caseCategoryCode from caseCategoryName as display the result.
And, since these are String values, the subtraction fails.
I suspect you don't want to subtract them at all and instead you want to display the two vaues separated by a hyphen. Like this:
INPATIENT - IP
To do that you can escape the hyphen so that Thymeleaf does not treat it as a subtraction operator:
th:text="${case.caseCategoryName} - ${case.caseCategoryCode}"
I am trying to get the following link to work:
http://localhost:8001/name/jason/grey
and the routes definition:
{"/name/([a-zA-Z]+)/([a-zA-Z]+)", [{controller, "stuff"}, {action, "getStudentNames"}, [{firstname, '$1'}, {lastname, '$2'}]]}.
and then in my controller
getStudentNames('GET', [FirstName, LastName])->
{output, "ok"}.
I get the following error message
CRASH REPORT Process <0.313.0> with 0 neighbours exited with reason: no function clause matching boss_router_controller:'-index_and_extract_params/1-fun-0-'([{firstname,'$1'},{lastname,'$2'}], []) line 258 in gen_server:terminate/7 line 812
Seems I am not getting it right with the routes definition, any help?
Finally got it working, should in case there is anyone with the same issue. Instead of using list of tuples in the route definitions to define the parameters, use tuples separated by commas e.g
{"/name/([a-zA-Z]+)/([a-zA-Z]+)", [{controller, "stuff"}, {action, "getStudentNames"}, {firstname, '$1'}, {lastname, '$2'}]}.
I'm trying to create a link with a dynamic link like:
<g:link action="${nextDashboardUriMap.nextAction}" params="${["$nextDashboardUriMap.queryStringId": "$entityId" ]}">
${entityName}
</g:link>
where nextDashboardUriMap.queryStringId contains xyz and entityId contains 12.
I was expecting url of the link to be http://website.com/controller/action?xyz=18 but <g:link/> consistently gives me http://website.com/controller/action?xyz.
I have tried replacing entityId with a string literal.
You don't need to use GStrings here, you can simply say
<g:link action="${nextDashboardUriMap.nextAction}"
params="[(nextDashboardUriMap.queryStringId):entityId]">
It seems that it may be this bug: GRAILS-9774 - the value is lost if key in params map is of type GString. Converting the key to String should resolve your problem:
<g:link action="${nextDashboardUriMap.nextAction}"
params="${[("$nextDashboardUriMap.queryStringId".toString()): "$entityId" ]}">
(...)
how about
<%
Map paramsMap = [:]
paramsMap[nextDashboardUriMap.queryStringId] = entityId
%>
<g:link action="${nextDashboardUriMap.nextAction}" params="${paramsMap}" >${entityName}
</g:link>
i'm searching for a name in an html page of facebook.
if I take the file html.txt like this:
html = open('html.txt','r').read()
soup = BeautifulSoup(html)
if I search for the name with find it seems to be ok, but if i Try searching with BS i cant find anything..
>>>html.find("Joseph Tan")
98939
>>>html[98700:99000]
'<div class="fwn fcg"><span class="fcg"><span class="fwb"><a class="profileLink" href="https://www.facebook.com/ASD.391" data-ft="{"tn":"l"}" data-hovercard="/ajax/hovercard/user.php?id=123456">Alex Tan</a></span> condivided the photo <a class="profileLink" '
>>> soup.findAll('div',{'class':'fwn fcg'})
[]
>>> soup.findAll('span',{'class':'fwb'})
[]
>>> soup.findAll('a',{'class':'profileLink'})
[]
>>>
Someone can help me? thanks a lot
EDIT: RE-CREATED HTML PAGE
html page
It is working as below:
print soup.find_all('div', class_=['fwn','fcg'])
OUTPUT:
[<div class="uiHeaderActions rfloat _ohf fsm fwn fcg"><a class="_1c1m" href="#" role="button">Segna tutti come già letti</a> · <a accesskey="m" ajaxify="/ajax/messaging/composer.php" href="/messages/new/" id="u_0_8" rel="dialog" role="button">Invia un nuovo messaggio</a></div>, <div class="uiHeaderActions fsm fwn fcg">Segna come già letto · Impostazioni</div>, <div class="fsm fwn fcg"><a ajaxify="/settings/language/language/?uri=https%3A%2F%2Fwww.facebook.com%2Fshares%2Fview%3Fid%3D10152555113196961&source=TOP_LOCALES_DIALOG" href="#" rel="dialog" role="button" title="Usa Facebook in un'altra lingua.">Italiano</a></div>]
According to ==>this link, this is the style of how to search classes and other HTML elements using BS. Please check.
There were two problems.
1. The way you wrote is not matched with the link above I provided. May be you are not using updated version of BS.
2. There are two classes 'fwn' and 'fcg'. So you have to give their names in a list and this is how I got the output.
Same is is applicable for 'span' and 'a' as below:
print soup.find_all('span', class_='jewelCount')
print soup.find_all('a', class_='_awj')
Your given 'span' with class 'fwb' and given 'a' with class 'profileLink' was not found.Because, they are not present in the HTML.
You can check by printing all spans and a's.
Write print soup.find_all('a') and print soup.find_all('span')* to check on your own.
Hope this will help, if not, write again! :)
In my erb file I have this:
"name": "<%= o =*('a'..'z'),*('A'..'Z')
string = o.sample(10).join %>",
That assigns a random generated string as the value to the name element as the key.
It is generating the random string fine but in RubyMine IDE it says
"expected <% or <%= or ;"
at the place of the second "*" in the code? Why is that and how to fix it?
Also more importantly, How can I can a prefix to this generated string? so for example let's say this generates string of abcDef But I need it to be MyPrefix_abcDef
The IDE is correct, there is an error. You need to replace
o =*('a'..'z'),*('A'..'Z')
with
o =[*'a'..'z'] + [*'A'..'Z']