java - loops binary tree in jstl -
i create binary tree , display result in jsp conditions.
each node has 4 elements (id, question, answer, , leftnode rightnode)
if user clicks "yes", program goes left of tree , if answers "no" right of tree.
for example, initial question "you're man?" if answers "yes" go left , page view "you're singer?" if answers "no" page displays "you're french? ".
in java, original question.
cursor [i]. getquestion ()
then yes
cursor [i] getquestion. getleftnode ()
and no
cursor [i]. getrightnode (). getquestion
until the, works normally, when want loop until there no longer issue by
<c:when test="${not empty cursor[i].getquestion() }">
the program stops @ first loop , stops cursor not empty
here complete code jstl
<c:choose> <c:when test="${not empty cursor[i].getquestion() }"> <c:if test="${param.btn eq 'oui'}" var="oui"> <c:set var="cursor" value="${cursor[i].getleftnode() }" scope="session"></c:set> <c:set var="i" value="${i+1 }" scope="session"></c:set> </c:if> <c:if test="${param.btn eq 'non'}" var="non"> <c:set var="cursor" value="${cursor[i].getrightnode() }" scope="session"></c:set> <c:set var="i" value="${i+1 }" scope="session"></c:set> </c:if> </c:when> </c:choose> <c:out value="${cursor.getquestion() }"></c:out>
thank you
rather using methods ${cursor.getquestion() }
have use property names this: ${cursor.question }
p.s. , make sure have proper getter names (get should lower case)
Comments
Post a Comment