5

Other than using Session Attributes is there a way to pass values from an Entity View to Page View when using DXA Java? This is with reference to DXA 1.x (actually 1.0 or pre-release version of DXA Java) and SDL Tridion 2013 SP1.

We have tried using cookies and request scope attributes for passing info from Entity View to Page View, but since everything is within the same request/response flow neither approach seemed to work.

To give a better picture, this is the use case:

I have a SDL DXA Page with its corresponding Controller, EntityView and PageView. The purpose of this page is to receive a QueryString parameter that identifies the type of image. Based on the type of image being requested, the Controller fetches a random image of this type from a pool of images managed in SDL.

The Entity View gets the URL (and physical path) to the image file and it passes it to the Page View. The Page View then reads the image file from the file system and outputs a binary stream in response, effectively serving the image.

The URL of this page is used as the src attribute of an Image used in an email template. So depending on the type of email (registration confirmation, reminder, thank you, etc.) a different image is loaded dynamically on request. Each time the same email is re-opened the user may see a different image (picked from the pool of same type of images).

Currently we are passing the image path as a Session Attribute from the Entity View to the Page View, however sometimes the Page View is unable to get the Session Attribute value resulting in an error and no image being returned.

So we are looking for an alternate way of passing the image URL from the Entity View to the Page View.

  • Maybe you can edit your question and specify why Session Attributes is not working for you and what other way you are looking for and why? – Bart Koopman Sep 29 '17 at 7:54
  • @BartKoopman I have tried to explain the use case and current problem we are facing to the best I could. I hope someone can suggest a better way of achieving what I am trying to do. Thanks. – Husain Zahid Sep 29 '17 at 10:57
  • Why do you determine the image path in an Entity View, but not let the Entity View render the image? It is quite common to use an Entity Model/View/Controller as a kind of widget which dynamically selects items, but normally the Entity View then takes care of rendering those items too (it might delegate rendering to other Entity Views). – Rick Pannekoek Oct 3 '17 at 19:08
  • On re-reading I see that you are abusing a Page View to serve an image. It’s a bit dubious design, by why would you even use an Entity View at all in this case? Your Page View can access the Entity Model directly if needed. – Rick Pannekoek Oct 3 '17 at 19:37
  • @RickPannekoek thanks for responding. Isn't DXA doing something similar to serve all images in general? If not how are images/css/js resources served by DXA since these are not published or store onto the filesystem directly by the deployer? What would be the optimal approach to serve images? – Husain Zahid Oct 4 '17 at 13:01
1
  1. Using a Page Model/View/Controller to serve images is abuse of these concepts. DXA serves images (or static content items in general) using a StaticContentInterceptor instead of a Model/View/Controller.

  2. You can do without Entity View (because the Entity Model is not really rendered anyways); Entity Models are integral part of the Page Model an can be accessed directly in the Page View: pageModel.getRegions().get("Main").getEntities().get(0)

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.