2

I'm having some issues recovering a Tridion component content in a controller in my DXA project.

The component schema is called AutocompleteResults and it has 2 fields:

  • hotels: Component Link of Hotel (a schema including name, category, email... and other text fields) allowing multiple values.
  • destinations: Component Link of City (a schema including name and country) allowing multiple values.

I created some components using the schema Hotel and some using City. Then, I created a component AutocompleteResults using the schema AutocompleteResults, and added the hotel and city components as component links.

I also created a component template adding "Default Component Template Finish Actions" and "Render Component Presentations" and vinculating the schema AutocompleteResults. I configured it like this:

ComponentTemplate configuration

I also created a page template Autocomplete adding "Render Page Content" and "Default Page Template Finish Actions" and configured it like this:

PageTemplate configuration

Then, I created a page Autocomplete inheriting from the above page template and adding the presentation Component/Component template created before.

AutocompletePage1

AutocompletePage2

I have published the page, publish settings and components (this last ones just in case), but I can't get the information in my DXA .NET project.

This is the controller and the action I created, but entity is not being populated:

Controller

NullEntity

The view AutocompleteResults referenced in the component template is also created, and it's registered in the CoreAreaRegistration (I've tried also without the last parameter "Page").

CoreAreaRegistration

The model AutocompleteResults has the same structure as the schema of the component in Tridion:

AutocompleteResultsModel

Could anyone help me to see what I'm doing wrong?

Thanks a lot!

Mer

  • 1
    Can you try below one on your Area Registration page and confirm - RegisterViewModel("AutocompleteResults", typeof(AutocompleteResults), controllerName: "AutocompleteResults"); – Sayantan Basu Jul 30 '18 at 11:48
  • @SayantanBasu thank you for your quick response, but it's still not working... – Mer Jul 30 '18 at 12:00
  • Your template needs to be DD4T/DXA, and I think you are using the "Default" TBBs used for html generation... You need the TBBs that generate JSON/XML instead, so DXA can read the models.... – Jaime Santos Alcón Jul 30 '18 at 12:34
  • Anything interesting in the DXA log file (if you set log level to DEBUG)? – Rick Pannekoek Jul 30 '18 at 20:38
  • What does your AutoCompleteResults Schema look like? In particular: what is the Root Element Name and what are the field names? – Rick Pannekoek Jul 30 '18 at 20:39
1

Your log file reveals that there is an HTTP Request directly to the Entity Action of your custom Entity Controller. That is not the way that Entity Controllers are normally used and no CM Model Mapping will occur in that manner.

Entity Controllers are normally invoked as part of the Page rendering flow. You can let your custom Entity Controller inherit from EntityController and override the EnrichModel method to dynamically populate your Entity Model (after regular CM model mapping happened).

I’m not sure how you expect your Controller to be used and what is generating the HTTP Request on your Controller’s Entity Action?

UPDATE:

If your Component is part of a Page, you don’t need a custom Controller in order to make CM model mapping work.

If you want to retrieve the Component as a separate entity, you will have to use a dynamic CT, so the Component gets published as separate entity (Dynamic Component Presentation). DXA currently does not have a built-in Controller action to retrieve Entity Models (for DCPs) separately, but you can create a custom Controller action to do that. Your custom Controller (inherited from BaseController) can use ContentProvider.GetEntityModel to obtain the Entity Model for the DCP.

  • What I really need is to recover the content of my AutocompleteResults component created in Tridion and map it into a model. Is there another way to do that without a custom Entity Controller? I was just testing this option by calling the controller directly from the browser. – Mer Aug 2 '18 at 9:20
  • Updated the Answer with some more information. – Rick Pannekoek Aug 2 '18 at 15:11
  • I've tried adding this in my controller imgur.com/neGJbun, but I get this error: "No Component Template data available for DCP 'tcm:47-724/tcm:47-723-32'. Republish the DCP to ensure it uses the new DD4T 2.0 DCP format." I've tried republishing the component template, the component, the publish settings... but I always get that error. Could you check if my component template it's well configured? Thank you very much for your patience! imgur.com/0nE4eQO imgur.com/zDnvIlk imgur.com/2guGeFv – Mer Aug 3 '18 at 7:38
  • Your CT should be set to “dynamic” (4th dropdown from the top labelled “Las presentaciones de componente ...”). Then, when you Publish the Component, you will see that a DCP gets resolved (next to or instead of Pages which contain the Component). – Rick Pannekoek Aug 3 '18 at 19:45
  • Hi again. I made that change after some research before you tell me and it made no difference :(. Any other ideas? Thanks! – Mer Aug 6 '18 at 13:55
0

First of all your component template needs to be dynamic and not published as part of the page. And you will need to use default DXA TBBs that will output json format to the Broker database.

  • It should work fine with embedded CPs too. – Rick Pannekoek Jul 30 '18 at 20:34
  • What is the default DXA TBBs, @Stefan Klasnic? Do you mean I should remove "Default Component FInish Actions" and "Render Component Content" and use a DD4T Template? Which one, "DD4T.Templates.Merged", "Generate Dynamic Component"...? – Mer Jul 31 '18 at 7:55
  • No, "Render Page Content" and "Render Component Content" are the default DXA TBBs. These take care of rendering the Page/Component as JSON (either DD4T JSON or DXA R2 JSON in DXA 2.0). – Rick Pannekoek Jul 31 '18 at 8:07
  • Then I guess if I've already added "Default Component FInish Actions" and "Render Component Content", the template configuration is fine. – Mer Jul 31 '18 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.