using querybuilder to find a component, is there any way to get the components model? | Community
Skip to main content
Level 8
Apr 24, 2021 4:21 PM UTC
Solved

using querybuilder to find a component, is there any way to get the components model?

If you find a component using querybuilder, it gives you a ValueMap of the properties. The components in question already have a full model defined. Is there any way to get the model back, instead of the value map?  

Hand writing method to copy each field into the value map would be onerous and fail as soon as the components model changed.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Ritesh_Mittal
Ritesh_MittalAccepted solution
New Participant
Apr 25, 2021 9:25 AM UTC
 

Hi @tb3dock ,

 

If I have understood your question correctly then you can always adapt a resource to your Model class like below-

 

for (Hit hit : searchResult.getHits()) {
Resource resource = hit.getResource();

MySlingModel myModel = resource.adaptTo(MySlingModel.class);

}

 

Let me know if it helps.

 

Thanks,

Ritesh

2 replies

Ritesh_Mittal
Ritesh_MittalAccepted solution
New Participant
Apr 25, 2021 9:25 AM UTC
 

Hi @tb3dock ,

 

If I have understood your question correctly then you can always adapt a resource to your Model class like below-

 

for (Hit hit : searchResult.getHits()) {
Resource resource = hit.getResource();

MySlingModel myModel = resource.adaptTo(MySlingModel.class);

}

 

Let me know if it helps.

 

Thanks,

Ritesh

Translate
TB3dockAuthor
Level 8
Apr 25, 2021 3:09 PM UTC

Interesting, I would not have guessed you could do this. There are plenty of articles on the querying, but none on what the various fields of the resultant object mean, and how they can be used (other than trial and error)

Translate