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

Hi ,

Thanks for your pointers . 

Regarding RequestAttribute , am not sure if requestParameter will map to requestAttribute  . Will give it a try though  . will keep you posted.


Just an update ,

So I gave a try injecting request params to my model vis RequestAttribute injection , but doesn't seem to work ..

Inject @Named(field name from form) @Source("request-attributes") .

 

I guess in Springs there is a class RequestDataBinding which does exactly this . I wonder if something like this also exists for sling ?