我的很多自定义组件都扩展了 EssentialsListComponent 。相同的标准 HST 组件有许多有用的参数,例如 pageSize
和 sortOrder
(通过控制台输入),我目前必须在我的类中单独处理这些参数。这个过程非常乏味并且容易出现人为错误。
如何将所有标准参数一次性应用于自定义 HST 组件中的 HST 查询?例如,像下面这样的东西会很可爱:
@Override
protected <T extends EssentialsDocumentListComponentInfo> HstQuery buildQuery(HstRequest request, T paramInfo,
HippoBean scope) {
scope = request.getRequestContext().getSiteContentBaseBean();
try {
HstQuery hstQuery = request.getRequestContext().getQueryManager().createQuery(scope);
hstQuery.applyParameters(paramInfo);// paramInfo should already includes pageSize, sortOrder etc. right?
} catch (Exception e) {
}
}
最佳答案
您可以扩展 EssentialsDocumentListComponentInfo
接口(interface),假设 MyDocumentListComponentInfo
也是一个接口(interface)。
在 MyDocumentListComponentInfo
接口(interface)上重写您希望具有默认值的方法,例如 pageSize
和 sortOrder
。
假设您希望 pageSize 的默认值为 20 而不是 10。为此,您可以使用以下代码:
@Parameter(name = "pageSize", required = true, defaultValue = "20", displayName = "Page size", description = "Nr of items per page")
int getPageSize();
有了这个,您不需要在控制台中声明该属性,除非您想要自定义值。
现在,在您扩展的组件中,在类声明上方声明以下注释:
@ParametersInfo(type = MyDocumentListComponentInfo.class)
现在您的代码应该可以正常工作,并且每次需要配置的参数更少。
关于java - 如何在子组件中包含标准HST组件的所有参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30613513/