Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

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

TB3dock
Level 8
Level 8

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.

1 Accepted Solution
Ritesh_Mittal
Correct answer by
Community Advisor
Community Advisor
 

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

View solution in original post

2 Replies
Ritesh_Mittal
Correct answer by
Community Advisor
Community Advisor
 

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

View solution in original post

TB3dock
Level 8
Level 8

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)