<c:if test=""> doesn't work [duplicate] - jstl

This question already has answers here:
jstl <c:if> tags not working in jsp file, getting error in tomcat 7
(2 answers)
Closed 5 years ago.
I'm new to JSTL and for some reason, I can't get the test line to work. Here is the simplified code I'm using:
<c:if test="${hasChild}">
test
</c:if>
when I use
${hasChild}
it prints true to the screen but it doesn't woork on the test line and I don't know why. Can anyone help please?

Have you declared hasChild prior to the test taking place? i.e.
<c:set var="hasChild">*Something which makes this value true*</c:set>
<c:if test="${hasChild}">
test
</c:if>

Related

How to separate number with commas in Thymeleaf [duplicate]

This question already has answers here:
How to format the currency in HTML5 with thymeleaf
(4 answers)
Closed 3 years ago.
How to display Number with comma every 3 numbers in Thymeleaf?
For example, 12345678 I want to display this number as 12,345,678 . I got my data from Spring Boot
<div class="value" th:text="${price}"></div>
You can try this way:
<div class="value" th:text="${#numbers.formatDecimal(price, 0, 'COMMA', 0, 'POINT')}"></div>

Xpath subscript returning all nodes, not just the requested one [duplicate]

This question already has answers here:
How to select first element via XPath?
(2 answers)
How to select the first element with a specific attribute using XPath
(9 answers)
Closed 3 years ago.
I'm trying the following XPath:
//*[local-name()='SN102'][1]
Using XPathTester, I saved my scenario
http://www.xpathtester.com/xpath/94ee37e08960247a7bf0619d38c52bee
Not every HL1Loop has a SN102.
Otherwise, I could this:
//*[local-name()='HLLoop1'][1]//*[local-name()='SN102']
I have simplified the sample data down to the following:
<ns0:X12_00401_856 xmlns:ns0="http://schemas.microsoft.com/BizTalk/EDI/X12/2006">
<ns0:HLLoop1>
<ns0:SN1>
<SN102>1</SN102>
<SN103>EA</SN103>
<SN108>AC</SN108>
</ns0:SN1>
</ns0:HLLoop1>
<ns0:HLLoop1>
<ns0:SN1>
<SN102>2</SN102>
<SN103>EA</SN103>
<SN108>AC</SN108>
</ns0:SN1>
</ns0:HLLoop1>
</ns0:X12_00401_856>
The result is coming back with all nodes, not just the first one:
<?xml version="1.0" encoding="UTF-8"?>
<result>
<SN102>1</SN102>
<SN102>2</SN102>
</result>
How do I select the first node only. Seems simply, and I'm sure I've done it before, but not working today.
I have a "Vendor Simulator" program that is building fake 856 data to send back, and I want to increase the first quantity only to force some error handling logic.
Just select the first element of the whole nodelist
(//*[local-name()='SN102'])[1]
The original query //*[local-name()='SN102'][1] would have selected the first SN102 if there had been several siblings of the same name.

starts with and ends with in xpath [duplicate]

This question already has answers here:
XPath testing that string ends with substring?
(5 answers)
Closed 2 years ago.
Following is how the element looks like on the page:
I want all the li which comes right after General Engineering Courses. General [COURSE_NAME] Courses is common text on other pages as well.
So basically I want all the li which come right after GENERAL [COURSE_NAME] Courses.
I wrote the following XPath, but unfortunately, it's causing DOMException while executing the XPath on Chrome.
//*[starts-with(text(), 'GENERAL') and ends-with(text(), 'COURSES')]
Page: http://catalog.fullerton.edu/content.php?catoid=16&navoid=1922
You need use XPath Axes, the following-sibling
//p[starts-with(strong,'GENERAL ') and substring(strong, string-length(strong)-7)=' COURSES']/following-sibling::ul/li

Thymeleaf concatenation preprocessing:

I hope someone can help me with my problem with Thymeleaf.
The case is that I need to do preprocessing with thymeleaf, the first one does it correctly, but inside that first preprocessing I need to get another field from the model, but when I add the field preprocessinf inside another preprocessing it gives me a type error
Could not parse as expression: "$ {rules ["
If I do this, it works fine
rules[__${row.index}__].propertiesValues[]
Failure to insert the other preprocessing
rules[__${row.index}__].propertiesValues[__${rules[__${row.index}__].bookingRuleDescriptor.propertyDescriptors[__${iter.index}__].name}__]
I hope you can help me.
Thank you!!
There is only one preprocessing pass. You get that error because of the mismatched __. For example, the first time it tries to preprocess:
propertiesValues[__${rules[__${row.index}__]
The expression it tries to evaluate is __${rules[__, which is not a valid thymeleaf expression.
The options you have are:
1) If this expression is not being used in a th:field, you shouldn't be doing preprocessing anyways. You can simply use:
${rules[row.index].propertiesValues[rules[row.index].bookingRuleDescriptor.propertyDescriptors[iter.index].name]}
2) If you are using this in a th:field, you'll have to use th:with to evaluate some of your expressions before hand. Something like:
<th:block th:with="i=${row.index}, j=${rules[row.index].bookingRuleDescriptor.propertyDescriptors[iter.index].name}">
<input type="text" th:field="*{rules[__${i}__].propertiesValues['__${j}__']}" />
</th:block>

JSTL cutsom date format using fmt tag [duplicate]

This question already has an answer here:
How to format date in JSTL
(1 answer)
Closed 7 years ago.
I need a date format like this.
11 November ,2015
I have tried using fmt tag.
<fmt:formatDate value="${Attr['DATE']}" type="both" dateStyle="long" />
the output is
November 11, 2015 12:00:00 AM.
How can i do that? Please help me.
Can i use any kind of pattern attribute?
Hint: fmt:formatDate has a pattern attribute too.
Try <fmt:formatDate pattern="dd M ,yyyy" value="${Attr['DATE']}" /> or <fmt:formatDate type="date" dateStyle="long" value="${Attr['DATE']}" />

Resources