Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

AEM 6.4 Connect java file with HTML File

Avatar

Level 5

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

Current Java code:

1679533_pastedImage_0.png

html code

1679558_pastedImage_1.png

Folder Structure:

1679565_pastedImage_0.png

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

1679566_pastedImage_0.png

     - 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>

1 Accepted Solution

Avatar

Correct answer by
Level 10

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.

View solution in original post

13 Replies

Avatar

Level 10

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.

Avatar

Level 5

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

Avatar

Employee

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

Avatar

Correct answer by
Level 10

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.

Avatar

Level 10

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

HTLSlingModel.png

Avatar

Level 5

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

Avatar

Level 5

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

1680300_pastedImage_2.png

Number 8 seems like a typo to me.

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

1680301_pastedImage_3.png

textfield and textarea doesn't reflect.

Avatar

Level 5

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.

Avatar

Level 10

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

Avatar

Level 5

Ok thanks!

Here another, how do you restrict the path item?

1680323_pastedImage_0.png

So that user is restricted to a certain folder only.

1680322_pastedImage_7.png

Thanks!

Avatar

Level 10

Not sure but try these -

Option#1:   aem-touch-ui-validation/pathbrowser.html at master · nateyolles/aem-touch-ui-validation · GitHub

&lt;pathbrowserD
  jcr:primaryType="nt:unstructured"
  sling:resourceType="granite/ui/components/foundation/form/pathbrowser"
  fieldLabel="Required and allow non existing path"
  fieldDescription="Try entering an external URL"
  rootPath="/content/aem-touch-ui-validation"
  required="{Boolean}true"
  allowNonRootPath="{Boolean}true"
  allowNonExistingPath="{Boolean}true"
  name="./pathbrowserD"/&gt;

If this doesn't suffice, then write custom code to forcefully delete the chosen path that doesn't belong to the restricted folder and display message to let user know pick the specific path only:

Option#2:

AEM Touch UI Dialog Validation New Best Practice: Use Foundation-Validation

Avatar

Level 5

Thanks. I'll read that after I'm done with this image metadata cheers!