5

In my DXA 1.5 installation, I added two basic device families just to demo it and test it is working correctly

enter image description here

In the log files I see that it is resolving to the correct device type, in this case iphone

This is an 'iphone' becuase of conditions.....

enter image description here

I've added views for Iphone and Ipad (article.iphone.jsp & article.ipad.jsp)

enter image description here

However I am always served the default view

1 Answer 1

2

There is an inconsistency in how DXA resolves normal and contextual views.

Short story

  1. Set dxa.web.views.folder=/ in dxa.properties.
  2. Add your views to <YOUR_WEBAPP>/src/main/resources/WEB-INF/Views/<PATH_TO_VIEW>.

In your case: /src/main/resources/WEB-INF/Views/Core/Entity/Article.iphone.jsp.

Notice that this will brake contextual view resolve from modules. We don't have any in DXA though.

Screenshot of my IDE


Long story

Contextual views are being checked whether they exist in classpath${dxa.web.views.folder}/WEB-INF/Views/<ViewName>. dxa.web.views.folder is set to /META-INF/resources/ by default, so for Article.iphone view the path is classpath:/META-INF/resources//WEB-INF/Views/Core/Entity/Article.iphone.jsp.

At the same time, ViewResolver tries to resolve the view from either classpath:/WEB-INF or <webapp>/WEB-INF (one level up from the classpath). For JARs it also tries classpath:/META-INF/resources/WEB-INF.

So while for views from JAR, both default check&resolve will find a JAR in a /META-INF/resources/WEB-INF, for web application check in META-INF will pass but resolve fail. You need either to set both to classpath root in a webapp or create your own module to solve this issue. See short story. :)

3
  • Thanks @Alexey - It seems I need to have the views in both places (unless I am doing something wrong). Without having Article.iphone.jsp in both \src\main\resources\WEB-INF\Views\Core\Entity and \src\main\webapp\WEB-INF\Views\Core\Entity it does not work Commented Jul 27, 2016 at 18:02
  • The one in \src\main\webapp\WEB-INF\Views\Core\Entity is used for rendering, but without the other one it always uses the default view Commented Jul 27, 2016 at 18:10
  • That's what I said actually. One from webapp folder is picked up by ViewResolver while the second is used for a check if you have a family-specific view. To solve that issue you need to point that check to your classpath root and put your view at the same place. This works perfectly for me: dl2.joxi.net/drive/2016/07/29/0000/1998/1998/98/a3469b0fe1.jpg
    – Alexey
    Commented Jul 29, 2016 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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