排序列时SearchContainer未知属性

时间:2015-08-25 11:27:48

标签: java jsp liferay

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

enter image description here

这是searchContainer

中的view.jsp
<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中的view_details.jsp看起来像这样

<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>

现在当我点击其中一个标题对view_details.jsp中来自不同实体的searchContainer中的结果进行排序时,我收到错误 Unknown property 'xxx' on class com.test.portlet.model.impl.SampleImportLogImpl' 。< / p>

据我所知,portlet与实体SampleImportLog绑定。我想通过view_details.jsp中遗漏的某些属性对SampleImportLogImpl中的结果进行排序。但是,此属性存在于我Sample中显示的实体view_details.jsp中。

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

1 个答案:

答案 0 :(得分:0)

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

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

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

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

<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 view_details.jsp中,我设置了iteratorURL

<liferay-ui:search-container emptyResultsMessage="sample-empty-results-message"  orderByType="<%= orderByType %>" iteratorURL="<%=iteratorURL %>">

它工作正常。现在,我可以根据Sampleview_details.jsp实体的不同属性对搜索容器结果进行排序。