使用 DisplayTag 库框架通过 Struts2 进行分页

发布于 2024-07-17 07:51:05 字数 1410 浏览 3 评论 0 原文

我想为我的应用程序的某些类应用分页,其中我使用 spring、struts2 和 struts2。 冬眠。 这里我从welcome.jsp 文件中调用action 类。 它具有以下代码:

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

现在我的 java 的 allCountry.action 类具有以下代码:

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.jspcountry.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] 在对象类型中查找属性“id”时出错 “java.lang.String”。 原因:未知属性“id”

此类错误的解决方案是什么?

I want to apply pagination for some class of my application, in which i am using spring, struts2 & hibernate. Here i am calling action class from welcome.jsp file. It has following code :

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

Now my allCountry.action class of java has following code :

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

It fetches the data properly, that i confirmed by printing countryList object. But now i am redirecting from SUCCESS to country.jsp. The code of country.jsp is :

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

Now at the time executing my application i am getting run time error like :

javax.servlet.ServletException: javax.servlet.ServletException:
Exception: [.LookupUtil] Error looking up property "id" in object type
"java.lang.String". Cause: Unknown property 'id'

What is the solution to this type of error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

梦里梦着梦中梦 2024-07-24 07:51:05

您需要在您的操作中为您的国家/地区列表提供一个吸气剂。

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

You need to have a getter for your countryList in your action.

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;
}
孤芳又自赏 2024-07-24 07:51:05

我对 Struts2 不熟悉,但似乎 DisplayTag 在任何范围内都找不到您的countryList。

我没有看到您将 CountryList 放入 from 或 request 中。 如果我不正确,您可能需要指定表单名称,例如

I'm not familiar with Struts2 but it seems that DisplayTag can't find your countryList in any scope.

I don't see you putting countryList in from or request. If I'm not right may be you need to specify form name like
<display:table list="${yourStrutsFormName.countryList}" ...

煞人兵器 2024-07-24 07:51:05

您需要使“countryList”对 DisplayTag 可用,例如通过在您的操作中执行以下操作

   request.setAttribute("countryList", countryList);

(除非有更聪明的 Struts2 方法来执行此操作)。 我认为您可以通过使其实现 ServletRequestAware

您还需要确保您的 Country 类具有 id 和 name 属性。

You need make "countryList" available to DisplayTag, e.g. by doing something like:

   request.setAttribute("countryList", countryList);

in your action (unless there's a cleverer Struts2 way of doing this). I think you can get hold of the request in your action by making it implement ServletRequestAware

You also need to make sure that your Country class has id and name properties.

小ぇ时光︴ 2024-07-24 07:51:05

使用以下代码。使用名称属性代替列表属性。

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

Use the following code.Instead of list attribute use name attribute.

<display:table name="countryList" requestURI="CountryAllAction" pagesize="3">
 <display:column property="id" title="ID" />
 <display:column property="name" />
</display:table>
触ぅ动初心 2024-07-24 07:51:05

你不需要做任何事情,只需在显示标签名称中使用列表变量即可

<display:table name="yourListnameinaction">

</display>

u dont need to do any thing just use list variable in display tag name i.e

<display:table name="yourListnameinaction">

</display>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文