首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >排序列时的SearchContainer未知属性

排序列时的SearchContainer未知属性
EN

Stack Overflow用户
提问于 2015-08-25 11:27:47
回答 1查看 572关注 0票数 0

我有一个portlet sampleimportlog_WAR_Testportletview.jsp,其中在数据库查询的searchContainer中显示实体SampleImportLog。我得到了结果

这是searchContainer in view.jsp

代码语言:javascript
复制
<liferay-ui:search-container emptyResultsMessage="sampleImportLog-empty-results-message"  orderByType="<%= orderByType %>">
        <%

        List<SampleImportLog> allSampleImportLogs = SampleImportLogLocalServiceUtil.getSampleImportLogs(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
        List<SampleImportLog> sampleImportLogsPerPage = ListUtil.subList(allSampleImportLogs, searchContainer.getStart(),searchContainer.getEnd());
        List<SampleImportLog> sortableSampleImportLogs = new ArrayList<SampleImportLog>(sampleImportLogsPerPage);
        if(Validator.isNotNull(orderByCol)){
            //Pass the column name to BeanComparator to get comparator object
            BeanComparator comparator = new BeanComparator(orderByCol);
            if(orderByType.equalsIgnoreCase("asc")){
                //It will sort in ascending order
                Collections.sort(sortableSampleImportLogs, comparator);
            }else{
                //It will sort in descending order
                //Collections.reverse(sortableSampleImportLogs);
                Collections.sort(sortableSampleImportLogs, Collections.reverseOrder(comparator));
            }

        }
        searchContainer.setResults(sortableSampleImportLogs);
        searchContainer.setTotal(SampleImportLogLocalServiceUtil.getSampleImportLogsCount());

        %>

            <liferay-ui:search-container-row
                className="com.test.portlet.xxx.model.SampleImportLog"
                keyProperty="importId"
                modelVar="sampleImportLog" escapedModel="<%= true %>"
            >


                <portlet:renderURL var="viewSampleImportDetailsURL">
                    <portlet:param name="mvcPath" value="/html/sample/sampleimportlog/view_details.jsp" />
                    <portlet:param name="uuid" value="<%= sampleImportLog.getUuid() %>" />
                </portlet:renderURL>

                <portlet:actionURL name="deleteSampleImport" var="deleteSampleImportURL">
                    <portlet:param name="importId" value="<%= String.valueOf(sampleImportLog.getImportId()) %>" />
                    <portlet:param name="uuid" value="<%= String.valueOf(sampleImportLog.getUuid()) %>" />
                </portlet:actionURL>

                <liferay-ui:search-container-column-text
                    name="uuid"
                    property="uuid" 
                    orderable="true"
                    orderableProperty="uuid"
                    href="<%= viewSampleImportDetailsURL %>"
                />

                <liferay-ui:search-container-column-text
                    name="File Name"
                    property="fileName"
                    orderable="true"
                    orderableProperty="fileName"
                    href="<%= viewSampleImportDetailsURL %>"
                />

                <liferay-ui:search-container-column-text
                    name="Imported By"
                    property="fullNameImporter"
                    orderable="true"
                    orderableProperty="fullNameImporter"
                    href="<%= viewSampleImportDetailsURL %>"
                />

                <liferay-ui:search-container-column-text
                    name="Date Of Import"
                    property="dateOfImport"
                    orderable="true"
                    orderableProperty="dateOfImport"
                    href="<%= viewSampleImportDetailsURL %>"
                />

                <liferay-ui:search-container-column-text>
                    <liferay-ui:icon-delete url="<%= deleteSampleImportURL.toString() %>" 
                        message="<%= \"Delete this import\" %>" 
                        confirmation="<%= \"Are you sure you want to delete this import? \" +
                                \"This will delete the import log as well as all the samples imported in this batch from the file \" 
                                + sampleImportLog.getFileName()+\".\" %>"
                    />
                </liferay-ui:search-container-column-text>
            </liferay-ui:search-container-row>

        <liferay-ui:search-iterator />
    </liferay-ui:search-container>

当我点击行时,我得到了uuid (from the first column)。使用这个uuid,我查询另一个名为Sample的实体,并在另一个页面中显示详细信息,比如view_details.jsp。我可以在sample entities中的searchContainer中类似地列出view_details.jsp。在此之前一切都很顺利。

searchContainer in view_details.jsp如下所示

代码语言:javascript
复制
<liferay-ui:search-container emptyResultsMessage="sample-empty-results-message"  orderByType="<%= orderByType %>" >

<%

    List<Sample> samplesByuuid = SampleLocalServiceUtil.getSamplesByuuid(uuid);
    List<Sample> samplesByuuidPerPage = ListUtil.subList(samplesByuuid, searchContainer.getStart(),searchContainer.getEnd());
    List<Sample> sortableSamplesByuuid = new ArrayList<Sample>(samplesByuuidPerPage);
    if(Validator.isNotNull(orderByCol)){
        //Pass the column name to BeanComparator to get comparator object
        BeanComparator comparator = new BeanComparator(orderByCol);
        if(orderByType.equalsIgnoreCase("asc")){
            //It will sort in ascending order
            Collections.sort(sortableSamplesByuuid, comparator);
        }else{
            //It will sort in descending order
            Collections.sort(sortableSamplesByuuid, Collections.reverseOrder(comparator));
        }

    }
    searchContainer.setResults(sortableSamplesByuuid);
    searchContainer.setTotal(samplesByuuid.size());
%>
<liferay-ui:search-container-row
            className="com.test.portlet.xxx.model.Sample"
            keyProperty="sampleDbId"
            modelVar="sample" escapedModel="<%= true %>"
        >

<liferay-ui:search-container-column-text
                name="uuid_"
                property="uuid_"
                orderable="true"
                orderableProperty="uuid_"

            />

<liferay-ui:search-container-column-text
                name="container"
                property="container" 
                orderable="true"
                orderableProperty="container"
            />
...
...
</liferay-ui:search-container-row>

    <liferay-ui:search-iterator />
</liferay-ui:search-container>

现在,当我单击其中一个标头对来自不同实体的Unknown property 'xxx' on class com.test.portlet.model.impl.SampleImportLogImpl'.中的searchContainer中的结果进行排序时,就会得到错误的view_details.jsp

我所理解的是,portlet绑定到一个实体SampleImportLog。我要按view_details.jsp中缺少的一些属性对结果进行排序。但是,该属性存在于实体Sample中,我在view_details.jsp中显示了该实体。

如何解决这个问题?是否需要为来自不同实体的详细信息创建单独的portlet?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-26 11:22:13

我在SampleImportLog搜索容器中显示view.jsp实体。单击一行后,我将在Sample搜索容器中显示view_details.jsp实体。当我试图对搜索容器结果排序时,在com.test.portlet.model.impl.SampleImportLogImpl'.类上得到错误未知属性'xxx‘。

我发现我不需要为来自不同实体的细节创建单独的portlet。portlet不绑定到任何实体,我可以在portlet中显示任何实体。

该错误是由于未能在view_details.jsp中维护搜索容器的上下文造成的。因此,在搜索容器上执行的任何操作都会导致导航到portlet默认页面view.jsp。并且显示在view.jsp搜索容器中的实体没有我试图在view_details.jsp中对搜索容器排序的属性。

因此,为了在view_details.jsp中维护搜索容器的上下文,我定义了

代码语言:javascript
复制
<liferay-portlet:renderURL  varImpl="iteratorURL">
        <portlet:param name="mvcPath" value="/html/sample/sampleimportlog/view_details.jsp" />
        <portlet:param name="uuid" value="<%= uuid %>" />
</liferay-portlet:renderURL>

然后在searchContainer in view_details.jsp中,设置iteratorURL

代码语言:javascript
复制
<liferay-ui:search-container emptyResultsMessage="sample-empty-results-message"  orderByType="<%= orderByType %>" iteratorURL="<%=iteratorURL %>">

而且效果很好。现在,我可以根据Sample实体在view_details.jsp中的不同属性对搜索容器结果进行排序。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32202806

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档