jstl forEach iterate with no certain number of steps - foreach

I want to create a forEach that begin at 0 and ends at count; that variable count can change inside loop. I set count to 4 than, inside loop change it to 8 but that didn't change number of loops.
<c:set var="count" value="4"></c:set>
<c:forEach begin="0" end="${count}">
<c:out value="message"></c:out>
<c:if test="${count < 6}">
<c:set var="count" value="8"/>
</c:if>
</c:forEach>
Result: message five time, expected 9

I don't think you can do this.
Because JSTL is converted to java code finally, the interpreter would directly take the value of the count when reached to the line. Thus, it is equivalent to:
<c:forEach begin="0" end="4">
...
</c:forEach>

Related

What is the difference between makelist() and create_list() in MAXIMA?

I have seen that there are two similar functions to create lists in maxima: create_list() and makelist(). In both cases, the arguments can be
(<an expression>, <a variable>, <the initial value>, <the final value>, < the step>) or
(<an expression>, <a variable>, <a list of values for the variable>).
What is the difference between these two functions? I have tried a couple of examples and they seem to work in the same way:
makelist(i^i,i,1,3); -> [1,4,27]
create_list(i^i,i,1,3); -> [1,4,27]
makelist(i^i,i,[1,2,3]); -> [1,4,27]
create_list(i^i,i,[1,2,3]); -> [1,4,27]
If you wish, you can create your own function, with its own syntax, in maxima.
For example, there is no operator ".." but this makes it happen.
infix("..",80,80,expr,expr,expr);
You can then define the semantics ...
here I just call a function named range.
(a..b):= range(a,b)
This doesn't provide for all the embroidery that you might like.
I think a superior technique for syntax and semantics is to enhance the "for" loop as in this example:
for i:1 thru 5 do collect i;
which returns [1,2,3,4,5]
All the varied mechanisms for "for", including step size, limit, iterating through sets, etc. can then be included in computing a list explicitly comprising a range. The code for this is about 7 lines of lisp, inserted into the source code for "parse-$do".
I also allow
for i in [a,b] summing f(i) ; which returns f(b)+f(a).
This enhancement is redundant for the (few) people who are comfortable with map, cons, lambda, apply, append ... in Maxima.
The code, which can be read in to any maxima, is here.
https://people.eecs.berkeley.edu/~fateman/lisp/doparsesum.lisp

Why does JSTL parseNumber parse 1000.0 to 10000?

I have an input form where I want to insert some numbers and calculate some results. So my input field looks like
<fmt:parseNumber var = "a" type = "number"
value = "${object.someAttribute}" integerOnly = "true"/>
<input type="number" name="someAttribute" required pattern="[0-9]" value="${a}" />
I want to do following: at first visit, a user should insert a number (Integer). In the calculation, all values are Double to prevent casting side effects. When the site is refreshed / the user wants to repeat the calculation, the input field should be preset with the recently used value. Therefore I tried fmt:parseNumber to parse the Double value from the object to an Integer.
At first try I omitted integerOnly = "true" but got an Error (as '1000.0' is not a valid input, that's understandable as I specified pattern="[0-9]").
But with integerOnly set, it changes the value from 1000.0 to 10000. What am I doing wrong? How could I parse it to achieve my goal?
If you are using EL 2.2+, you can simply convert a double to integer by invoking a non-getter method on your Double object:
${yourDouble.intValue()}
See:
https://stackoverflow.com/tags/el/info

XSLT: Test if string is contained in a sequence

I have two sequences of strings. I wanna wether get a sequence which is reduced by those items, which are also in sequence 2; or to compare those two sequences and get the information, if at least one item of sequence 1 is also in sequence 2.
A simple compare ( $seq1 = $seq2 ) works for me only with a sequence of numbers, or am I doing something wrong?
Glad about any help! :)
The = operator should suffice, see example http://xsltransform.net/gWmuiJ6 which does
<xsl:variable name="seq1" select="'foo', 'bar', 'foobar'"/>
<xsl:variable name="seq2" select="'a', 'foo', 'b'"/>
<xsl:variable name="seq3" select="'a', 'b', 'c'"/>
<xsl:value-of select="$seq1 = $seq2, $seq1 = $seq3"/>
and outputs true false.
If you want some value based intersection then see also http://www.xsltfunctions.com/xsl/functx_value-intersect.html.

Error parsing thymeleaf template with "1 < 0"

Maybe is a stupid question but I failed to retrieve information from Google.
As the title say, I get a stack trace if a try to parse this simple line:
<span th:if="${1 < 0}">
The error is:
org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 43; The value of attribute "th:if" associated with an element type "null" must not contain the '<' character.
But if i try this:
<span th:if="${0 > 1}">
Everything is fine, my question is: Why I get this error?
I believe is related to my lack of experience with Java and thymeleaf, but I don't get why by just changing the position of the elements it work as I expect (return always false).
It is a bug in the parsing of the expression (as checking if 1 is lower than 0 is forbidden by some parser rule) or is just a weird XML parsing issue?
Thank you to all who will even just read.
You have to escape the symbol by using
< for <
> for >
≤ for <=
≥ for >=
So your code should look like :
<span th:if="${1 < 0}">
You can find the whole doc about this in the 'Using Thymeleaf' tutorial on their website, in the comparators-and-equality section.
≤ for <=
≥ for >=
didn't work for me. I had to use:
<= for <=
>= for >=
It seems that ≤ and ≥ are not accepted as well-formed XML.
This solves the "IllegalStateException: Cannot handle (8804) '≤' " problem.
I have come with same problem, but shows different exception and my code is here:
<div class="text-center m-1" th:if="${totalCount} > 0">
<span> Showing user # [[${startCount}]] to [[${endCount}]] of [[${totalCount}]] </span>
</div>
Here is my stack trace:
Caused by: org.attoparser.ParseException: Cannot execute GREATER THAN comparison: operands are "null" and "0"
So, I have changed to:
<div class="text-center m-1" th:if="${totalCount} != 0">
<span> Showing user # [[${startCount}]] to [[${endCount}]] of [[${totalCount}]] </span>
</div>
It works.

Ant flaka: modify each elements of a list

I have this list:
<c:let>
a = list('a','b','c')
</c:let>
How can i modify each elements for that list?
I need something like:
for (int i = 0; i < a.length; i++) {
a[i] += 'd';
}
I looked in the tutorial, but the examples show only how to retrieve a list element, not how to modify it.
So, how can i modify list elements, iterating on it?
Thanks!
There is (currently) no function which lets you manipulate lists. All you could do is
<let>
a = list('a', 'b', .. ) ; your list
b = list() ; empty list
</let>
<for var=" item " in=" a ">
<let>
x = some-el-expression( item ) ;
b = append(b, x)
</let>
</for>
<let>
a = b
</let>
Work has started which allows one to use functions with arguments - besides the convenience functions (append() and other functions listed in section 3.6 of the manual). Other work has also been started to allow you to plugin your own functions (would require Java programming - providing functions via Groovy or (J)Ruby needs some research).

Resources