So this works ok in HTL/sightly
<h3>${properties['my-field-name-here'] @CONTEXT='text'}</h3>
But how do I access this value in Java?
I have this code in my class but I cannot see "my-field-name-here" in the list. Thoughts? Thanks!
ValueMap test = resource.getValueMap()
Solved! Go to Solution.
Views
Replies
Total Likes
If its a Sling Model, then use ValueMapValue annotation
@ValueMapValue
private String mailAddress;
Details here: https://techrevelhub.wordpress.com/2017/03/18/sling-model-annotations/
If its a Service/Servlet, use
resource.getValueMap().get('my-field-name-here', String.class);
Here Resource needs to be the exact node where property exists. Like jcr:content
This link has few examples for various types of properties: https://www.tabnine.com/code/java/methods/org.apache.sling.api.resource.ValueMap/get
If its a Sling Model, then use ValueMapValue annotation
@ValueMapValue
private String mailAddress;
Details here: https://techrevelhub.wordpress.com/2017/03/18/sling-model-annotations/
If its a Service/Servlet, use
resource.getValueMap().get('my-field-name-here', String.class);
Here Resource needs to be the exact node where property exists. Like jcr:content
This link has few examples for various types of properties: https://www.tabnine.com/code/java/methods/org.apache.sling.api.resource.ValueMap/get
Hi @jayv25585659 : I suppose you are using sling model to retrieve the field value as you have shared the sightly snippet.
Can you share how you are calling the sling model from your HTL please? It has to be something like this where myFieldNameHere would be the getter method which gives the field value of my-field-name-here.
<div data-sly-use.info="org.example.app.components.info.Info">
<p>${info.myFieldNameHere}</p>
</div>
Or you can refer this link to see if you are doing it correctly.
https://experienceleague.adobe.com/docs/experience-manager-htl/content/java-use-api.html?lang=en#bun...
Sling Model documentation: https://sling.apache.org/documentation/bundles/models.html
@jayv25585659 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes