Hello I have something like this:
<c:when test='${results.fieldNames[rowStatus.index] == "NSN"}'>
<fmt:formatNumber value="${cell}" pattern="${commas_with_no_decimal_pattern}" var="tArr"/>
</c:when>
Where Im setting a formatted # to var="tArr". I want to use a string formatter and set it to var="tArr". But I only know how to set it up like this:
<ctl:stringFormat format="####-##-###-####">${dispVal}</ctl:stringFormat>
How can I set this formatted string to a var?
Had to set var as a property in the ctl:stringFormat tld
Related
I have this value
<c:set var="string1" value="SS4444"/>
What I am try to achieve is to get the numbers only (4444) from the above variable. I can use substring, but the index value might change, ie it can be 'SS4444', 'S4444', 'SSS444', so cant rely on static index.
Thanks in advance
Split it with regex.. (substringAfter is not proper for this..):
<c:forEach var="string1" items="${fn:split(yourstring, '^\w*')}">
<c:set var="string2" value="${string1}"/>
</c:forEach>
You can try with replace function as:
<c:set var="strng" value="SS4444"/>
<c:set var="strng1" value="${fn:replace(strng,'S','')}"/>
<#assign reasonValue="xxx.ftl">
and I call it like:
<#include "${reasonValue}">
and I get output like:
Rejected - Something
how can I now use split on this ouput because I would like to get just Something as output
I tried:
<#list "${reasonValue}"?split("-") as sValue>
${sValue}
</#list>
but problem is that instead of real value i get name of ftl file...
Assign output of include to some variable and then use split on this variable.
<#assign xx>
<#include reasonValue>
</#assign>
<#list xx?split("-") as sValue>
${sValue}
</#list>
If you need to show only part of the string after "-" then use substring and index_of.
${xx?substring(xx?index_of("-") + 2)}
i have two arrays (strings delimited with commas) and i made a foreach loop on one of this vars
i need to be able to access to the other string with the foreach index like
<c:set var="name" value="Zara,nuha,roshy" />
<c:set var="name2" value="Zara2,nuha2,roshy2" />
<c:forEach items="${name}" delims="," var="name" varstatus="i">
<c:out value="${name}"/><br>
</c:forEach>
i need to access name2 values, in the name foreach, is it possible without doing another foeach?
The varstatus variable you are using contains a value "index" that you can use.
But, you can't operate on a string like that (not that I know of at least).
First, you need to convert name2 to a proper array or list. Then you can access it inside the for loop:
${name2list[i.index]}
Now, how to convert it to an array? How about the split function?
<%#taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="name2list" value="${fn:split(name2, ',')}"/>
This can be done, contrary to some previous comments.
See the following example based on the question:
<c:set var="names" value="Zara,nuha,roshy" />
<c:set var="names2" value="Zara2,nuha2,roshy2" />
<c:forEach items="${names.split(',')}" varStatus="i" var="name" >
${name} : ${names2.split(',')[i.index]}<br/>
</c:forEach>
Essentially we're using a string split function with expression language to get a string array from list comma separated values. Within the loop we the get the second value from the names2 array by using the varStatus index. I believe this accomplishes the task.
I have a jstl value,
<c:forEach items="${detail}" var="u">
<c:set value="${u.content}" var="c"/></c:forEach>
I want to set the variable in jquery equal to the var = "c".
How could I do that?
<script>
<c:forEach items="${detail}" var="u">
<c:set value="${u.content}" var="c"/>
var whatever = ${c};
</c:forEach>
<script>
You might need to JS escape it, quote it, etc. depending on what's actually in the variable, which you don't mention. It's also not clear what "a variable in jQuery" is.
The bottom line is that if the JavaScript lives in a JSP, just use the value: the JS isn't evaluated until the response has been emitted, so mix-and-match, but be aware that it's pretty easy to create invalid JavaScript unless you take care to properly escape whatever value types you're emitting.
As an example, consider a Java String that contains a single quote: if you single-quote the Java value in JS you'd have invalid JS because you didn't JS-escape the string value.
the method given in the below code might be correct but the variable whatever would have only one value that also only during the last count of the for each loop would exist
<script>
<c:forEach items="${detail}" var="u">
<c:set value="${u.content}" var="c"/>
var whatever = ${c};
</c:forEach>
<script>
for instance if the loop for the variable detail is of list type that consists of string type objects in it like "A" , "B" ,"C" then in the case the value of the var whatever will be "C", this is because jstl is compile time language.
So the above code won't work in for each loop
the following code might help you out or atleast provide you a idea for same.
<script>
var whatever = new Array;
<c:forEach items="${detail}" var="u">
<c:set value="${u.content}" var="c"/>
for (var i=0;i<whatever.length;i++)
{
whatever[i]=${c};
}
</c:forEach>
<script>
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.