Search code examples
magnolia

How to access Magnolia v5.7 component property from Model java class


  • I have defined property in component dialog

enter image description here

  • How I can access this value from execute() method in model class?
  • Model class will request service at this url

Documentation discusses only how to access data within Model class, I need to pass url into Model class.

I can't send request from page by ajax, because service domain not exposed to extranet.


Solution

  • Your model class extends from RenderingModelImpl. Or at least it should :).
    Because of that there's a constructor that get passed current component node in and it's exposed to you via getNode() method.
    So assuming that when you click on Save changes in your dialog, the value gets persisted under unsubscribeUrl property, to access this value from execute() method:

    public String execute() {
        // read unsubscribe url
        String unsubscribeUrl = this.getNode().getProperty("unsubscribeUrl").getString();
    }