1

我的很多自定义组件都扩展了EssentialsListComponent。同一个标准 HST 组件有很多有用的参数,例如pageSizesortOrder(通过控制台输入),我目前必须在我的类中单独处理这些参数。这个过程很繁琐并且容易出现人为错误。

如何在我的自定义 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) {
}
}
4

2 回答 2

2

您可以扩展EssentialsDocumentListComponentInfo接口,假设MyDocumentListComponentInfo它也是一个接口。在MyDocumentListComponentInfo接口上覆盖您希望具有默认值的方法,例如pageSizesortOrder

假设您希望 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)

现在您的代码应该可以正常工作,并且每次需要配置的参数更少。

于 2015-07-07T13:21:45.560 回答
0

见:http ://www.onehippo.org/library/concepts/component-development/hstcomponent-parametersinfo-annotation.html

如果你扩展一个组件,你会继承它的参数。|如果将其设置为在 hst 配置中继承,则可以访问这些参数。您还可以重用或扩展现有的 parameterinfo 接口以使代码更简洁。如果参数信息中不包含参数,那么您仍然可以按名称引用它。

请注意,文档链接适用于版本 10。如果您需要 7.9 或更早版本的文档,请单击文章顶部的历史记录链接。

于 2015-06-04T09:19:22.687 回答