The jstl equals method doesn't work for me for some reason. The code is
<span>${fromerror}</span>
<span>${fromerror eq 'mandatoryCriteria.criteria.from'}</span>
yet the result is like this
mandatoryCriteria.criteria.from
false
I'm using jstl 1.2
More specifically I'd need it in if statement but the result is the same
<c:if test="${not empty fromerror and fromerror eq 'mandatoryCriteria.criteria.from'}">
I solved it. The problem was that fromerror variable actually contained something like this
<span id="from.errors">mandatoryCriteria.criteria.from</span>
Which browser evaluated as "mandatoryCriteria.criteria.from". And that's why eq didn't work
Related
I recently started a new job that uses cucumber/Gherkin along with selenium. I was trying to create a XPath for a specific element. The xml looks slightly like this...
<p>
<div class="slds-text-title_bold slds-m-bottom_x-small ncc-input-label">
Amp
</div>
<div class="slds-text-title_bold slds-m-bottom_x-small ncc-input-label required-field-label">
Voltage
</div>
</p>
I am looking to only get the div with the required field label in the class and text of "Voltage" So far this kinda works...
//div[contains(text(), "Voltage")] | //*[contains(class, "required-field-label")]
however I'm getting way too many false positives. Any time I change the pipe into "and" I get nothing. What am I doing wrong?
HCSloan
Try the following expression on your actual code, and see if it works:
//div[contains(#class, "required-field-label")][contains(text(), "Voltage")]
You can match the element using "and" like this:
//div[contains(#class, 'required-field-label') and contains(text(), 'Voltage')]
Why the block never reaches "conditionTrue"? I have printed both the variables
authorEmail and scase.authorEmail and they are same string. If I use literal like 'abc#yahoo.com' to test the condition , it works but not if both the c:if params are variables.
<c:forEach var="scase" items="${section.subSectionList.get(0).SCaseList}">
<c:set var="authorEmail" >
<sec:authentication property="principal.email" />
</c:set>
<c:if test = "${authorEmail == scase.authorEmail}" >
<option>conditionTrue</option>
</c:if>
</c:forEach>
UPDATE - I got it to work by making these changes.
I commented out the entire c:set tag. Instead I added these line -
<sec:authentication var="principal" property="principal" />
My test condition was then :
<c:if test = "${principal.email == scase.authorEmail}" >
<option>conditionTrue</option>
</c:if>
And this worked. However, the reasoning behind it still baffles me. Any insight, much appreciated.
I am parsing string to number for comparison with zero(0). But getting weird result.
<fmt:parseNumber type ="number" var="parsedNumber" value="${noInStringFormate}"/>
<c:if test="${parsedNumber gt 0}">
Perform some action
</c:if>
Ex. for String "10.20" its parsed to Number 10.20.
But for String "0.23" its parsed to Number 0(zero) instead of 0.23
Even I tried by setting integerOnly="false" though its false by default. But its didn't work.
any idea on this?
Thanks for help.
Is it possible to write this in freemarker.
<input type="checkbox" value="Available ?" checked="<#if ${status}=='Available'>true<#else>false</#if>"/>
For now it throws exception
I want html checkbox to be checked if status property equals to "Available".
How to do this in freemarker?
<#if ${status}=='Available'> has a syntactical error (that the error message that you haven't included points to, I'm certain): you can't use ${...} inside FreeMarker tags (well, except inside string literals, but whatever). It should be just <#if status == 'Available'>. But, the simples solution for what you want is:
checked="${(status == 'Available')?c}"
or if you have an older FreeMarker then:
checked="${(status == 'Available')?string('true', 'false')}"
I know this works: <c:out value="${model.testhash['A']}"/>
but I need something like:
<c:out value="${model.testhash[${model.testkey}]}"/>
Is this possible?
Have you tried
${model.testhash[model.testkey]}
In general the ${ } only delineates the JSTL expression, you don't need to escape the lookup for the model.testkey lookup as well, so it is also possible to do:
${model.testhash[model.condition ? 'A' : 'B']}
.. just as an example.