HelloTag.Java
public class HelloTag extends SimpleTagSupport {
@Override
public void doTag() throws JspException, IOException {
JspWriter out = getJspContext().getOut();
ArrayList outerList = new ArrayList();
ArrayList innerList = null;
for (int i = 0; i < 5; i++) {
innerList = new ArrayList();
innerList.add("1");
innerList.add("Name");
outerList.add(innerList);
}
for (int i = 0; i < outerList.size(); i++) {
for (int j = 0; j < innerList.size(); j++) {
out.println(innerList.get(j));
}
}
}
}
In JSP File,
There is following code snippet:
<body>
<ct:Hello></ct:Hello>
</body>
When I run the JSP file, this file showing the accurate result; but
I want to take the decision of every value that come from custom tag class
such as
<c:set var="name" scope="" value=""/>
<c:choose>
<c:when test="${name == 1}">
This is Your ID:-
</c:when>
<c:otherwise>
This is Your Name
</c:otherwise>
</c:choose>
The above code is the just for sake of example. please update me how take decision on each value that comes form custom tag class.
Other way to explain my problem is that, I want to store every value in a variable , and then take a decision about that value just using JSTL without Scriplet Tags focusing on the above scenario (HelloTag.Java )
It’s really not clear what you’re asking. But your tag, as it is, just loops through each inner list of an outer list (well, in fact, I guess it should do that, but it has a bug, so it doesn’t).
You don’t need a custom tag to do that, since the JSTL
<c:forEach>tag does that already. Suppose you have an outerList stored in a request (or page, or session, or application) attribute:From your question, it seems to me that you shouldn’t have an inner list, though. Rather, the outer list should contains objects (instances of a
Personclass, for example) which have agetId()and and agetName()methods. The loop would thus be: