Hi, I have been working on a project where we have to generate the columns dynamically depending on the data coming from Server. We are using Kendo JSP taglib, so using java scriptlet to iterate over the list passed as model attribute to the JSP. Code snippet is as following:
<kendo:grid-columns>
<%
List fieldsList = (ArrayList)request.getAttribute("columnArr");
List columnsList = (ArrayList)request.getAttribute("fieldsArr");
String colName = "";
String fieldName = "";
for(int i=0;i<columnsList.size();i++){
colName = columnsList.get(i);
fieldName = fieldsList.get(i);
System.out.println("Col and Field values are:::"+colName+","+fieldName);
%>
<kendo:grid-column title="<%=colName %>"
field="<%=fieldName %>" headerAttributes="style=\"overflow: visible; white-space: normal;font-weight: bold;\"" />
<%} %>
</kendo:grid-columns>
Above code works fine if I use hard coded values in title and field attributes. but when I use variables as shown in above snippet, I get the following exception at runtime:
org.apache.jasper.JasperException: /WEB-INF/views/dashboardWidget.jsp(37,6) Unknown attribute type (String) for attribute title.
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:236)
at org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1164)
at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:821)
at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1530)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
Any idea why Title and field attribute are not accepting String variable as value? I have seen the Tag lib for Kendo:grid-column, title has type as String.
<attribute>
<description>The text that is displayed in the column header cell. If not set the field is used.</description>
<name>title</name>
<rtexprvalue>true</rtexprvalue>
<type>String</type>
</attribute>
Please also let me know if there is some other way to generate columns dynamically without using scriptlet.
Thanks & Regards,
Preeti
<kendo:grid-columns>
<%
List fieldsList = (ArrayList)request.getAttribute("columnArr");
List columnsList = (ArrayList)request.getAttribute("fieldsArr");
String colName = "";
String fieldName = "";
for(int i=0;i<columnsList.size();i++){
colName = columnsList.get(i);
fieldName = fieldsList.get(i);
System.out.println("Col and Field values are:::"+colName+","+fieldName);
%>
<kendo:grid-column title="<%=colName %>"
field="<%=fieldName %>" headerAttributes="style=\"overflow: visible; white-space: normal;font-weight: bold;\"" />
<%} %>
</kendo:grid-columns>
Above code works fine if I use hard coded values in title and field attributes. but when I use variables as shown in above snippet, I get the following exception at runtime:
org.apache.jasper.JasperException: /WEB-INF/views/dashboardWidget.jsp(37,6) Unknown attribute type (String) for attribute title.
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:236)
at org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1164)
at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:821)
at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1530)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
Any idea why Title and field attribute are not accepting String variable as value? I have seen the Tag lib for Kendo:grid-column, title has type as String.
<attribute>
<description>The text that is displayed in the column header cell. If not set the field is used.</description>
<name>title</name>
<rtexprvalue>true</rtexprvalue>
<type>String</type>
</attribute>
Please also let me know if there is some other way to generate columns dynamically without using scriptlet.
Thanks & Regards,
Preeti