1

spring、struts2、および休止状態を使用しているアプリケーションのクラスにページネーションを適用したいと考えています。ここでは、welcome.jsp ファイルからアクション クラスを呼び出しています。次のコードがあります:

<s:form action="marketing/allCountry.action">  
         <s:submit value="Click"></s:submit>  
         </s:form>  

今私allCountry.actionのJavaクラスには次のコードがあります:

public String executeAction() throws Exception {
        try {
            countryList = new ArrayList<Country>();
            countryList = this.countrySecurityProcessor.findByAll(0, null, null, null, null, false, false, null, null, null, null, 0);
            System.out.println("countryList = "+countryList);
            return ActionSupport.SUCCESS;

        } catch (Exception ex) {
            return ActionSupport.ERROR;
        }
}

countryListオブジェクトを印刷して確認したことを、データを適切に取得します。しかし、今は から にリダイレクトしSUCCESSていcountry.jspます。のコードcountry.jspは次のとおりです。

<display:table list="countryList" requestURI="CountryAllAction" pagesize="3">
    <display:column property="id" title="ID" />
    <display:column property="name" />
</display:table>

アプリケーションを実行しているときに、次のような実行時エラーが発生します。

javax.servlet.ServletException: javax.servlet.ServletException: 例外: [.LookupUtil] オブジェクト タイプ "java.lang.String" のプロパティ "id" の検索中にエラーが発生しました。原因: 不明なプロパティ'id'です

このタイプのエラーの解決策は何ですか?

4

5 に答える 5

2

アクションで countryList のゲッターが必要です。

List<Country> countryList = new ArrayList<Country>();

public String executeAction() throws Exception {
  try {
     countryList = this.countrySecurityProcessor.findByAll(0, null, null, null, null, false, false, null, null, null, null, 0);
     System.out.println("countryList = "+countryList);
     return ActionSupport.SUCCESS;

  } catch (Exception ex) {
     return ActionSupport.ERROR;
  }

}

public List<Country> getCountryList() {
  return countryList;
}
于 2009-04-22T16:27:12.247 に答える
0

表示タグ名にリスト変数を使用するだけで、何もする必要はありません。

<display:table name="yourListnameinaction">

</display>
于 2009-08-25T06:56:49.687 に答える
0

たとえば、次のようにして、「countryList」をDisplayTagで使用できるようにする必要があります。

   request.setAttribute( "countryList"、countryList);

あなたの行動の中で(これを行うための賢いStruts2の方法がない限り)。ServletRequestAwareを実装することで、アクションでリクエストを取得できると思います

また、Countryクラスにidプロパティとnameプロパティがあることを確認する必要があります。

于 2009-04-23T07:16:26.197 に答える
0

次のコードを使用します。list 属性の代わりに name 属性を使用します。

<display:table name="countryList" requestURI="CountryAllAction" pagesize="3">
 <display:column property="id" title="ID" />
 <display:column property="name" />
</display:table>
于 2009-07-01T11:05:24.143 に答える
0

私は Struts2 に精通していませんが、DisplayTag はどのスコープでも countryList を見つけることができないようです。

from または request に countryList を入れているとは思いません。私が正しくない場合は、次のようなフォーム名を指定する必要があるかもしれません <display:table list="${yourStrutsFormName.countryList}" ...

于 2009-04-22T16:22:31.227 に答える