AEM6:如何将参数从HTML传递到Java模型类中的方法?

AEM6:如何将参数从HTML传递到Java模型类中的方法?,aem,sightly,Aem,Sightly,我想将一个参数从html传递到WCMUse类 爪哇: HTML: ... ${componentHelper.methodA@parameter1=componentHelper.param} 不幸的是,看起来我无法将任何参数传递给该方法。有没有办法从html向WCMUse类传递参数?Java Use API不支持向getter方法传递参数。在使用类初始化期间,可以传递一次参数。看看这个例子,灵感来自: 只有从数据模板元素调用Use类时,此类参数才有意义(否则参数也可以在Use类中硬编码)。

我想将一个参数从html传递到WCMUse类

爪哇:

HTML:


...
${componentHelper.methodA@parameter1=componentHelper.param}

不幸的是,看起来我无法将任何参数传递给该方法。有没有办法从html向WCMUse类传递参数?

Java Use API不支持向getter方法传递参数。在使用类初始化期间,可以传递一次参数。看看这个例子,灵感来自:


只有从
数据模板
元素调用Use类时,此类参数才有意义(否则参数也可以在Use类中硬编码)。更多信息可以在前面提到的文档中找到。

Hi@Tomek@kmb我也面临类似的情况,我必须将一个java使用处理程序(我以前启动过)的属性传递给另一个java处理程序的激活。代码类似于,但在另一个处理程序java类slaId中,我得到的是null。如果我使用${anotherhandler.slaid},那么它不起作用;如果我使用${anotherhandler.slaid},那么它将作为字符串出现。我可以用什么方法来实现这一点?只是一个更新:对于Sling模型,您不必编写这样的激活方法,您只需使用
@inject
注入这些参数即可
public class ComponentHelper extends WCMUse {

    public void activate() throws Exception {}

    ...

    public String methodA(String parameter1) {
        ...
    }

    public String getParam() {
        String param = "";
        ...
        return param;
    }
}
<componentHelper data-sly-use.componentHelper="ComponentHelper" data-sly-unwrap />
...
<div>
    ${componentHelper.methodA @ parameter1=componentHelper.param}
    <!--/* Also tried: ${componentHelper.methodA @ componentHelper.param} */-->
</div>
<!-- info.html -->
<div data-sly-use.info="${'Info' @ text='Some text'}">
    <p>${info.reversed}</p>
</div>
// Info.java
public class Info extends WCMUse {

    private String reversed;
     
    @Override
    public void activate() throws Exception {
        String text = get("text", String.class);
        reversed = new StringBuilder(text).reverse().toString();
    }
  
    public String getReversed() {
        return reversed;
    }
}