我无法在 java List<.String> 的 struts 2 标签中形成表格 [英] I am unable to form table in struts 2 tags for java List<.String>

查看:15
本文介绍了我无法在 java List<.String> 的 struts 2 标签中形成表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 struts2 标签,我无法使用 struts 2 标签为以下代码创建表

I am using struts2 tags, i unable to create table using struts 2 tags for the following code

    List<String> list_Fields;
    List<QueryResult> iteratorquery;
    List<String> List_rows;

    for (int i = 0; i < iteratorquery.size(); i++) {
        System.out.println(iteratorquery.get(i));
        QueryResult list_result = iteratorquery.get(i);
        System.out.println(list_result.getFields());
        list_Fields = list_result.getFields();
        servletRequest.setAttribute("list", list_Fields);
        for (int g = 0; g < list_Fields.size(); g++) {
            System.out.println("Hello ListOFFields:" + list_Fields.get(g));
        }

        List_rows = list_result.getRows();
        for (int h = 0; h < List_rows.size(); h++) {
            System.out.println(List_rows.get(h));
            String rowList = List_rows.get(h);
            System.out.println("Hello i am in Rows:" + rowList);
        }
    }

提前致谢

推荐答案

不清楚您要做什么.

至少,您覆盖了list"请求属性的值.

At the very least, you're overwriting the value of the "list" request attribute.

据我所知,Java 代码可归结为以下内容,您想使用 S2 标签编写该代码.

As far as I can tell, the Java code boils down to the following, and you want to write that using S2 tags.

List<QueryResult> queryResults;
for (QueryResult result : queryResults) {
    List<String> fields = result.getFields();
    for (String field : fields) {
        System.out.println("field: " + field);
    }

    List<String> rows = result.getRows();
    for (String row : rows) {
        System.out.println("row: " + row);
    }
}

如果是这种情况,严格使用 S2 标记,您将通过普通的 S2 操作属性将 queryResults 公开给 JSP,并最终得到如下所示的内容:

If that's the case, strictly using S2 tags, you'd expos queryResults to the JSP via a normal S2 action property, and end up with something like the following:

<s:iterator value="queryResults" var="iq">
    <s:iterator value="iq.fields">
        <s:property />
    </s:iterator>

    <s:iterator value="id.rows">
        <s:property />
    </s:iterator>
</s:iterator>

正如 Umesh 所说,您可以使用迭代器玩一些有趣的游戏来帮助设计您的结果,尽管您可以使用 OGNL 和少量 CSS 更简洁地做到这一点.

As Umesh says, you can play some fun games with the iterators to help style your results, although you can do it more concisely using OGNL and a minimal amount of CSS.

<s:iterator value="results" status="status">
  <tr class="fields">
    <s:iterator value="fields">
      <td><s:property /></td>
    </s:iterator>
  </tr>

  <s:set var="rowsStyle" value="#status.last ? 'last' : ''" />
  <tr class="<s:property value='#rowsStyle'/>">
    <s:iterator value="rows" status="rowStat">
      <s:set var="tdStyle" value="#rowStat.last ? 'last' : ''" />
      <td class="<s:property value='#tdStyle'/>"><s:property /></td>
    </s:iterator>
  </tr>
</s:iterator>

这篇关于我无法在 java List&lt;.String&gt; 的 struts 2 标签中形成表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆