Skip to main content
Karl515
Level 5
Jan 30, 2019 9:43 AM UTC
Solved

AEM 6.4 Connect java file with HTML File

I've been reading quiet a few but still am not able to get it done.

Current Java code:

html code

Folder Structure:

I'm trying to read metadata (specifically) size of image in java and load it back to html.

     - I get my image via ${properties.fileReference}

     - I prefer Local, but By bundle is alright as long as explained.

------------------------------ WORKFLOW: ---------------------------------

     - Add image via

     - get file via ${properties.fileReference}

     - process in Java (local) (both sounds good too)

     - return width and height to .html. (ex. <div> ${javaClass.width} - ${javaClass.height} </div>

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Jan 30, 2019 3:01 PM UTC

See this document - we cover Granite Resource types and cover concepts like HTL/Sling Models:

Building Experience Manager Components using Granite/Coral Resource Types

I recommend that you go through the whole document too as it explains a lot of AEM Component concepts.

Also - I recommend placing your Java into a bundle - not a file in CRXDE lite.

13 replies

Gaurav-Behl
Level 10
Jan 30, 2019 12:11 PM UTC

Did you use  data-sly-use.<object_name>="com.adobe.cq.wcm.core.components.models.<SlingModelClass>" ?

check any core component and validate your code against it.

Translate
Karl515
Karl515Author
Level 5
Jan 30, 2019 12:43 PM UTC

Can you please provide a working example that I can base on, base on my problem above? Thanks!

Translate
Feike_Visser1
Adobe Employee
Adobe Employee
Jan 30, 2019 2:58 PM UTC

to me this only works if the java-class is part of a bundle

Translate
smacdonald2008
smacdonald2008Accepted solution
Level 10
Jan 30, 2019 3:01 PM UTC

See this document - we cover Granite Resource types and cover concepts like HTL/Sling Models:

Building Experience Manager Components using Granite/Coral Resource Types

I recommend that you go through the whole document too as it explains a lot of AEM Component concepts.

Also - I recommend placing your Java into a bundle - not a file in CRXDE lite.

Translate
smacdonald2008
Level 10
Jan 30, 2019 3:09 PM UTC

Just tested the package that is available with the Sling Model section and it works perfectly.

Translate
Karl515
Karl515Author
Level 5
Jan 31, 2019 1:31 AM UTC

@gauravb10066713 I did use "data-sly-use.hero" and that's sufficient according to this link. HTL Java Use-API

Translate
Karl515
Karl515Author
Level 5
Jan 31, 2019 1:32 AM UTC

Thanks. will do the reading.

Translate
Karl515
Karl515Author
Level 5
Jan 31, 2019 3:06 AM UTC

@smacdonald2008

What's the difference between sling:resourceType that has Coral and the once that are without? btw, I've tested the link and found an error

Number 8 seems like a typo to me.

and followed the instructions carfully to number 34 yet it doesn't seem to reflect.

textfield and textarea doesn't reflect.

Translate
Karl515
Karl515Author
Level 5
Jan 31, 2019 3:26 AM UTC

Update, I got to work. after I installed the complete package then doing the steps again. Maybe I was missing some coral component reference the first time.

Translate
smacdonald2008
Level 10
Jan 31, 2019 3:41 AM UTC

Granite types with coral in them are latest ones. Always use the latest ones on 6.4.

Translate