JSP code for Struts or JSTL tag
HI,
I am doing folling stuff in jsp code which I need to do using Struts or using JSTL tag, can any body have a related idea please share.
Below is the JSP code
<%
Object category = request.getAttribute("categoryDetails");
Hashtable<String, Hashtable<String, Integer>> cat = (Hashtable<String, Hashtable<String, Integer>>) category;
//out.print(cat.entrySet());
Set<String> functions = cat.keySet();
for(String fun : functions){
out.print("-----------");
out.print(fun);
out.print("-----------");
Hashtable<String, Integer> obj = cat.get(fun);
Vector<String> subFunction = new Vector<String>(obj.keySet());
Collections.sort(subFunction);
for(String str : subFunction){
out.print("#"+str+"-"+obj.get(str));
}
}
%>
Thanks in advance.
0
source to share
2 answers
You can use your own tag or create a temporary view structure like:
public class FunctionView {
String functionName;
List<SubFunctionView> subfunctions;
public FunctionView(String functionName, List<SubFunctionView> subfunctions) {
this.functionName = functionName;
this.subfunctions = subfunctions;
}
public String getFunctionName() {
return functionName;
}
public void setFunctionName(String functionName) {
this.functionName = functionName;
}
public List<SubFunctionView> getSubfunctions() {
return subfunctions;
}
public void setSubfunctions(List<SubFunctionView> subfunctions) {
this.subfunctions = subfunctions;
}
}
public class SubFunctionView {
String subFunctionName;
Integer value;
public SubFunctionView(String subFunctionName, Integer value) {
this.subFunctionName = subFunctionName;
this.value = value;
}
public String getSubFunctionName() {
return subFunctionName;
}
public void setSubFunctionName(String subFunctionName) {
this.subFunctionName = subFunctionName;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
}
Then you just loop through a method named List getFunctionsView () on your controller and use a simple nested jstl foreach loop.
Edit: We'll have to redo this part a bit.
0
source to share