SlingHttpServletRequest adapto custom sling model | Community
Skip to main content
Level 3
April 4, 2016

SlingHttpServletRequest adapto custom sling model

  • April 4, 2016
  • 1 reply
  • 4642 views

Hi There ,

 I'm using a custom sling model which i have annotated to be adapto from resource and singHttpServletRequest .

I have designed my model with the fields same as in my form ,

Example : My form has fields "Name", "Age," "Address"

my model also has these 3 fields all injected using "

@Inject @Named (field name from form)

"

I was assuming doing this would automatically map my request parameters to sling model if i perform request.adapto(customodel.class) .However this doesn't seem to work .

Is my understanding right in doing this ? Did i miss anything here ?

 

regards

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

kautuk_sahni
Community Manager
Community Manager
April 4, 2016

Hi

[Not a Solution but a good read]

Link:- http://www.wemblog.com/2014/11/how-to-use-sling-models-in-cq56.html

//How to use Sling Models in CQ5.6

I hope this would help you.

Thanks and Regards

Kautuk Sahni

Kautuk Sahni
Peter_Puzanovs
Community Advisor
Community Advisor
April 4, 2016
krisgummAuthor
Level 3
April 5, 2016

Once you have adapted your resource to slinghttprequest in sling model

All you need to do is using below code to get properties saved in node

ValueMap node = request.getResource().getValueMap();
String path = node.get("text", String.class);

Here I am retrieving 'text' property

Do see this article to get more idea:

http://adobeaemclub.com/sightly-pagination-component-using-sling-model-and-javascript-use-api-in-aem-6-1/


Thanks for the reply. 

But this approach is leading me to the impression that I need to manually map request Params to custom mode by get and set. 

I had already used annotations to map req Params to sling model shouldn't be performing it manually again. Spring requestdatabinder does exactly this. Waiting for the same in sling