m2doc

M2DOC - how to get parameter in Java service


I wrote a Java Service that I call like this in M2DOC my template :

{m:for pc | self.eAllContents(pa::PhysicalComponent)->select(p|p.name.equalsIgnoreCase('the parameter')).eAllContents(pa::PhysicalComponent)}
 {m:pc.ServerTable()}
 {m:endfor}

because I don't know how to get "the parameter" in my java Service.

In fact I would like to call my Java service like this :

{m:for pc | self.eAllContents(pa::PhysicalComponent)}
 {m:pc.ServerTable()}
 {m:endfor}

and get all PhysicalComponent with name 'the parameter' in the Java Service and not in the template.

Can someone help me please ?

Thanks


Solution

  • When you write a Java service for M2Doc/AQL (the query language used by M2Doc) the Java method should have at least one parameter but you can add more. You Java method should look like this:

    public SomeReturnType serverTable(PhysicalComponent component, String parameter) {
      ...
    }
    

    you can then call it like this in your template :

    {m:pc.serverTable('the parameter')}