Hello all,
I am trying to use the sling models taglib, and I am using the following input:
<%@ page import=“my.packages.TestModel" %>
<sling:adaptTo adaptable="${resource}" adaptTo="<%=TestModel.class.getName()%>"
var="model"/>
<div>${model.testString}</div>
But when doing this, I get the following exception:
java.lang.ClassCastException: java.lang.Object cannot be cast to
java.lang.String
at javax.servlet.jsp.tagext.TagData.getAttributeString(TagData.java:138)
at
org.apache.sling.scripting.jsp.taglib.tei.AdaptToTEI.getClassName(AdaptToTEI.java:26)
at
org.apache.sling.scripting.jsp.taglib.tei.AbstractVarTEI.getVariableInfo(AbstractVarTEI.java:78)
I would expect this to work? Is there any way I could get it to work like this?
It is nicer if I can import it so that my IDE has a clearer sight of which
classes are used in the jsp’s instead of having to write the class as a plain
string form:
<sling:adaptTo adaptable="${resource}" adaptTo="my.packages.TestModel"
var="model"/>
<div>${model.testString}</div>
(I am used to working with slice from cognifide, and am not trying out sling
models, in slice you could say <slice:lookup var=“model”
class=“<%=TestModel.class%>”/> without calling the getName but just using the
class object )
Thanks!
Roy