2

テーブルからデータを表示するために、liferay で検索コンテナを使用しています。うまくいきます!! コードのスニペットを次に示します。

<% 
List<testapp> pendingApprovals = ActionClass.getPendingLeaveApplications();
%>
<liferay-ui:search-container delta="20" emptyResultsMessage="No Results Found">
    <liferay-ui:search-container-results total="<%= pendingApprovals.size() %>"
       results="<%= ListUtil.subList(pendingApprovals , searchContainer.getStart(), searchContainer.getEnd()) %>" />

    <liferay-ui:search-container-row keyProperty = "empId" modelVar="search"
        className="com.test.mis.portal.model.testapp">
        <liferay-ui:search-container-column-text name='Leave Duration' value = '<%=String.valueOf(search.getLeaveDuration())%>'   href="" />
    </liferay-ui:search-container-row>

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

上記のコードを使用して、いくつかの条件に基づいて testapp テーブルからデータを表示します。同じコードで、行を追加してデータを表示したいと思います。この行のデータは、別のテーブルから取得する必要があります。つまり、2 つの異なるデータベース テーブルから検索コンテナーを使用してデータを表示したいと考えています。することは可能ですか?私の要件は、データが2つの異なるテーブルから取得されることです

要件のある編集セクション 私はいくつかのフィールドを持つ従業員テーブルを持っています 私はいくつかのフィールドを残して別のテーブルを持っています。empId は、Employee テーブルにマップされる Leave テーブルにあります。

休暇が保留中の場合にのみ、Leave テーブルのデータを表示する検索コンテナがあります。Leave テーブルと一致し、上記の条件を満たす Employee テーブルのフィールドのみを表示します。

4

2 に答える 2

2

多くの方法があるかもしれませんが、ここではすぐに頭に浮かぶいくつかを挙げます。

  1. 1 つの方法は、ServiceBuilder によって生成されたモデルを変更して、TestAppImpl次のような依存関係を含めることです。

    public class TestAppImpl extends TestAppBaseImpl {
    
        private List<OtherTableData> otherTableDataList;
    
        private OtherTableData otherTableData;
    
        // if want to retrieve a list of rows
        public List<OtherTableData> getOtherTableDataList() {
    
            // call a custom method created in the OtherTableDataLocalService
            // testAppId variable is available to TestAppImpl
            List<OtherTableData> otherDataList = OtherTableDataLocalServiceUtil.getOtherDataListByTestAppId(testAppId);
    
            return otherDataList;
        }
    
        // if want to retrieve just one row
        public OtherTableData getOtherTableData() {
    
            // call a custom method created in the OtherTableDataLocalService
            // testAppId variable is available to TestAppImpl
            OtherTableData otherData = OtherTableDataLocalServiceUtil.getOtherDataByTestAppId(testAppId);
    
            return otherData;
        }
    }
    

    上記の変更後、サービスを再構築する必要があります。

    JSPでは、次のものを使用できます。

    <liferay-ui:search-container-column-text name='Other table data name' value='<%=search.getOtherTableData().getName() %>' href="" />
    
  2. または、変更したくない場合TestAppImplは、JSP で次を使用できます。

    <liferay-ui:search-container-column-text>
    
    <%
    List<OtherTableData> otherDataList = OtherTableDataLocalServiceUtil.getOtherDataListByTestAppId(search.getTestAppId());
    
    for (OtherTableData tempData : otherDataList) {
    %>
    
        <%=tempData.getName() %>
        <%=tempData.getDescription() %>
        <%=tempData.getData() %>
    
    <%
    }
    %>
    
    </liferay-ui:search-container-column-text>
    
  3. 上記のポイント 2 のバリエーション:

    <liferay-ui:search-container-column-jsp
        name="otherDataFetch"
        path="/html/portlet/testApp/other_data.jsp"
    />
    

    そしてother_data.jsp、次のコードを使用できます。

    <%
    ResultRow row = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
    
    TestApp search = (TestApp) row.getObject();
    
    List<OtherTableData> otherDataList = OtherTableDataLocalServiceUtil.getOtherDataListByTestAppId(search.getTestAppId());
    
    for (OtherTableData tempData : otherDataList) {
    %>
    
        <%=tempData.getName() %>
        <%=tempData.getDescription() %>
        <%=tempData.getData() %>
    
    <%
    }
    %>
    

これがあなたが探していたものであることを願っています。さもなければ、少なくとも前進するためのヒントを与えるかもしれません.

于 2013-04-24T07:24:55.577 に答える
2

ここでの問題には 2 つの面があります。

  1. employeeId 外部キーを使用して、テーブル Leave および Employee からデータを取得できます。そのためのカスタム クエリは必要ありません。これは非常に簡単な作業です。
  2. 1 つのデータ/テーブルから取得できないデータを検索コンテナーに表示します。ご覧のとおり、「liferay-ui:search-container-row」属性は「className」という名前で、1 つのクラス名の値を取ることができます。これについて、私は2つのアプローチを見ることができます:

a) 休暇テーブルごとに結果を取得し、従業員 ID と保留ステータスでフィルター処理します。次に、各行で、employeeId を使用して再度 Employee インスタンスを取得し (EmployeeLocalServiceUtil.getEmployee(empId) によって)、次に従業員名などの Employeeye 属性を取得します。これには、jsp ファイルで手を汚す必要があります。

b) カスタム クラス (EmployeePendingLeaves など) を作成し、それを searchContainer のモデル クラスとして使用します。データベース モデルに含めないでください。Employee テーブルと Leave テーブルをスキャンする関数を作成し、結果行ごとに EmployeePendingLeaves インスタンスを作成するだけです。行の列ごとに変数/属性が必要です

于 2013-04-29T07:18:55.340 に答える