Expand my Community achievements bar.

Who Me Too'd this topic

Avatar

Former Community Member

I am experimenting with Sling Models. I followed Justin Edelson's advice about installing the API / Impl package from ACS, adding the instruction to the maven-bundle-plugin to generate the appropriate manifest header ... yadda, yadda

I defined an interface thus (note: the @Default values) :-

package com.aviva.aem.sling.models.telephonecontact; import javax.inject.Inject; import org.apache.sling.models.annotations.*; import org.apache.sling.api.resource.Resource; @Model(adaptables=Resource.class) public interface ITelephoneContact { @Inject @Optional @Default(values="Call Us") String getTitle(); @Inject @Optional @Default(values="TBA") String getContent(); @Inject @Optional @Default(values="For our joint protection all calls will be monitored.") String getMessage(); @Inject @Optional @Default(values="Calls to 0844 numbers are charged at 12p per minute. Calls to other numbers may vary.") String getCallCharges(); }

Packaged and installed my bundle then crufted up this JSPx to use it :-

<sling:findResources query="/jcr:root ... @sling:resourceType = 'avivapocs/components/telephone']" language="xpath" var="resources" /> <c:forEach var="telephoneResource" items="${resources}"> <sling:adaptTo adaptable="${resource}" adaptTo="com.aviva.aem.sling.models.telephonecontact.ITelephoneContact" var="model"/> <c:out value="${model.content}"/> </c:forEach>

So that you know, the findResources query DOES appear to find the FOUR telephone resources that are present in the location I used.

When I run this JSP I get :  TBA TBA TBA TBA (i.e. four default values)

If I change to ${model.title} I get : Call Us Call Us Call Us Call Us (default values again).

Looking in the JCR, there ARE different values for some of these, but none come thru.

I haven't mapped every property for the telephone resource in my interface yet (assumed I don't need to).

What am I doing wrong ??

Kind Regards

Fraser.

Who Me Too'd this topic