4

How to write a model in DXA JAVA for a schema having component link? The component link is generic and not based on any particular schema. Can this be achieved?

Adding some more details:

I have to display four Blocks (having links) on LHS side. On clicking on the LHS link, a corresponding section is diplayed on RHS side. The RHS content is different for each LHS link. For eg. 1st LHS link displays a form on RHS, 2nd Link displays a FAQ block on RHS and so on. So basically the views on RHS change on selection of LHS link.

I am doing this by creating one component which has fields like:

  1. LHS Link [text]
  2. RHS Component Link

Can this be achieved if I restrict my component links to only 4 schemas? In this case, how to write a model for these 4 different types of component links?

  • 1
    A better way to model this might be to have 4 separate Component Presentations on the page, plus perhaps a 5th one to generate the 'navigation' on the LHS (or a different Page Template/View to handle this). This enables your design to be much more flexible and modular and avoids any model mapping complexity – Will Price Aug 18 '15 at 12:16
  • i.e 4 CT for the RHS sections. and one CT for the LHS section which will hide/show or control the RHS side? – Huston Lopes Aug 18 '15 at 13:31
  • 1
    Yes exactly. This means that you can render any type of content in the RHS, and re-use these templates standalone if required. – Will Price Aug 18 '15 at 13:35
3

I can give you a view from the .NET DXA - I guess its similar for Java.

Do you want to create a hyperlink to the linked content? If so its rather simple, you simply have a property of type String or Link in your model, and the DXA will populate the model with a resolved link URL to the linked content.

Alternatively you may be looking to embed the linked content, although if this can be any schema you have a big problem, as you are potentially rendering any possible type of component, so your views are going to get very messy dealing with all the potential variations.

Nevertheless it may be possible by using a superclass as the model property type and allowing the DXA to inspect the linked content schema to determine which subclass to use when creating the model property value. This is how (in DXA 1.1) Multimedia objects of the correct type are created even if the schema field allows different linked schemas (YouTube video/Image/Download etc)

A final option is to use a semi-generic model type for the embedded content, and ensure that there is sufficient semantic markup on that model to enable it's key properties to be populated from different schemas. An example of this is the Teaser model, which has some generic properties like Headline, Link, Media, Text that are mapped from different fields in different schemas.

  • I have added more details in question now. If I restrict my component links to 4 types of schemas, what is the best way to achieve? – Huston Lopes Aug 18 '15 at 11:52
2

I had the opportunity to talk to Huston in person and that gaves another angel on the problem. I cannot answer the component link question, but we can solve the left hand side / right hand side content without using component links. Like Will suggested in his comment.

After careful inspection of the HTML design it turned out that the left hand links and right hand content are grouped in the same DIV element. So, the navigation on the left and the content on the right are gouped in a nice list of divs. This design screams to be modeled in four entity views (there are four content types in the right hand content part). The views might share a partial view for the left hand links part.

Having four content views we can also have four components, there is no need for an index component with component links.

Although not needed in this use case it would still be nice to try how to add fields from a linked component to a model.

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.