4

What would be the best approach to load content from external source? Only approach what I could come up with is to load this data in component and then update hippo bean (see example code bellow). But is there a better way? Is there some "hippo bean post processor" or "external source provider"?



    public class MyComponent extends BaseHstComponent {
        @Overrideenter code here
        public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
            SalesDocument doc = (SalesDocument)request.getRequestContext().getContentBean();

            ExternalData externalData = externalDataSource.getExternalData(doc.getId());
            doc.setValue(externalData.getValue());

            if (doc == null) {
                response.setStatus(404);
                return;
            }

            request.setAttribute("document",doc);
        }

    }


robert
  • 496
  • 4
  • 18

1 Answers1

2

There is no HippoBean post processor or external source provider at the moment. I guess in your case you want to fetch a piece of data from a remote system and you want to merge these two types of data so you can use them as one single unit in your template.

I think the above solution probably the easiest way to go. Or you can pass along both objects to the JSP / Freemarker template and render them if needed separately.

I do think that providing such a postprocessor might be a usefull addition especially in these kind of use cases.

Jeroen
  • 3,076
  • 1
  • 17
  • 16
  • Thx! Yes, I stick to the solution above. With one correction - in stead of updating HippoBean I will simply add external data object to request as another attribute - simple and clean approach. – robert Jul 05 '14 at 17:27
  • I've talk about this with the developers of the HST. They will add more dev friendly support for this by leveraging the Spring wired ObjectConverter bean. This wil be part of the 7.9.1 release of Hippo CMS. See https://issues.onehippo.com/browse/HSTTWO-3013 for more information. – Jeroen Jul 07 '14 at 09:15