0

I have an image added in the backoffice. I wish to call this image to get its properties (url, alt text) in a JSP page. So the idea i had is to try get this image in a controller so i can pass theses properties on my page.

This image is currently a SimpleBannerComponent which is a subcomponent defined in a component.

<attribute qualifier="checkimage" type="SimpleBannerComponent"
                               generate="true" autocreate="true">
                        <persistence type="property" />
                        <modifiers />
                        <description>Check image pictogram component to be displayed.</description>
                    </attribute>

Do you know how i can do this? How do you load medias as SimpleBannerComponent by code so i can pass this data to the JSP page.

Thanks!

Rushino
  • 9,415
  • 16
  • 53
  • 93

1 Answers1

1

Let's assume that your component is named TestComponent.

So, TestComponent has an attribute called "checkimage" which has the "SimpleBannerComponent" type(as it can be seen from your xml).

In order to display the image stored on the simple banner component you can simply add this into the jsp of your component(i.e testcomponent.jsp):

<a href="test"><img title="test"
    alt="test" src="${component.checkimage.media.url}"></a>

That way, the image will be shown on Content Page which contains your custom Component.

dj_frunza
  • 1,553
  • 3
  • 17
  • 28
  • but how checkimage.media.url get populated? it is automatic by hybris (using impex) or i have to populate it somehow in the controller? – Rushino Sep 25 '19 at 12:55
  • I expect that is not populated automatically. You should be able to set the image from SmartEdit or Backoffice(or if you want you can also create and run an Impex that does just that) – dj_frunza Sep 25 '19 at 13:04
  • The image is already set in the backoffice using ImpEx. The media exist. But how i tell the component to use the image set from the backoffice without having to set it manually in the controller. Is there a way? because right now even if the image is set, component.checkimage.media.url is empty. I had to manually call the mediaService to set it in the controller in a property. I expected to be able to avoid that but maybe its what need to be done. – Rushino Sep 25 '19 at 13:26
  • 1
    It should work without doing any additional steps in Controller. What needs to be investigated is why is it empty. Where exactly did you try to access component.checkimage.media.url ? In the JSP of the page or in the jsp of your Component ? The Controller that you are mentioning is a Page Controller or a Component Controller ? If it is a Component Controller you can debug in there and check exactly why is the value empty. – dj_frunza Sep 25 '19 at 13:43
  • Good questions. Guess my assomption of thinking the container of the component would be a component has been wrong. That explain why it doesn't work. It seem to be a JSP of the page and not the JSP of the component. The component which hold the SimpleBannerComponent right now doesn't have its own dedicated JSP or Controller. – Rushino Sep 25 '19 at 14:39
  • In my case, i am in a MultiStepCheckout page controller which call a addBankAccountPage JSP page. The image (which is a check image) seem to be shown directly in that page using bare img html tag. But what i try to do is to make it use a CMS component instead. I know SimpleBannerComponent have its own JSP but if i use that component.. How that component which is a SimpleBannerComponent is called in the addBankAccountPage JSP page? How i can tell the page to use that component at a specific location in the page and tell it to use the specific image from the backoffice? – Rushino Sep 25 '19 at 14:39