Struts2 显示嵌套LIST

 注:此处的嵌套LIST指的是一个LIST由多个其他LIST构成,组成LIST也可能包含多个LIST。

昨天在做jBPM开发时,想得到所有当前代办事项,发现jBPM的GraphSession只提供了findProcessInstances(long id)。

如何得到所有流程定义的所有实例呢,笨人笨办法:

List allInstance;

List pdList=jbpmContext.getGraphSession().findLatestProcessDefinitions();


 for(int i=0;i<pdList.size();i++)
  {
   ProcessDefinition pd=(ProcessDefinition)pdList.get(i);
   allInstance.add(jbpmContext.getGraphSession().findProcessInstances(pd.getId()));  
  }

 

 

问题出来了,如何在页面上用Struts标签显示allInstance列表中每个子列表中的项目呢?

查了半天,不得要领。

后来想想,还是直接看<s:iterator>标签的文档吧,果然有料:

 

http://struts.apache.org/2.1.2/struts2-core/apidocs/org/apache/struts2/components/IteratorComponent.html

  • status (String) - if specified, an instanceof IteratorStatus will be pushed into stack upon each iteration
  • value (Object) - the source to iterate over, must be iteratable, else an the object itself will be put into a newly created List (see MakeIterator#convert(Object)
  • id (String) - if specified the current iteration object will be place with this id in Struts stack's context scope
  •  

    看来id是代表迭代子的。

    于是使用struts标签如下:

    正在办理中的事项
    <table border="1" cellspacing="0" cellpadding="1">
      <tr><td>事项编号</td><td>公开办理业务名称</td></tr>

     <s:iterator value="allInstance" id="allInstance">
     <s:iterator value="allInstance">
       <tr>
           <td><s:property value="id"/></td>
           <td style="background: grey"><s:property value="processDefinition.name"/></td>
       </tr>
     </s:iterator>
     </s:iterator>
     </table>

     

    ok,大功告成。

    再查struts2的文档:

     

    Name
    Required
    Default
    Evaluated
    Type
    Description
    idfalsefalseStringDeprecated. Use 'var' instead
    statusfalsefalsefalseBooleanIf specified, an instanceof IteratorStatus will be pushed into stack upon each iteration
    valuefalsefalseStringthe iteratable source to iterate over, else an the object itself will be put into a newly created List
    varfalsefalseStringName used to reference the value pushed into the Value Stack

     

    id属性被取消?

    tnnd,struts就这样忽悠大伙。都吹JAVA如何一次编写,处处运行,吹牛说拥抱变化。我实在是没看出来哪里拥抱变化了。

    试试看。

    结果,fuck and shit,报错:

     Attribute var invalid for tag iterator according to TLD

     

    别对我说我用的版本不对。我每次建Struts项目时都是从对应版本的struts-all包中自带的blank-app导入开始的。

     

    唉!开源离产品化还差太远了。

    没有好文档,浪费的时间成本比商业软件还贵啊。

    特此提示

    1.<s:iterator>中,value属性引入要处理的bean,即action中返回的bean

    2.id属性作为迭代子,相当于get(i)

    3.在嵌套<s:iterator>中,使用外部iterator中id属性指定的变量,就相当于引用当前迭代得到的对象。

    由于当前迭代的对象也是一个list,所以接下来就可以访问该list中的对象了。

     

    按照此方法,每层list均使用id表示,可以嵌套任意多层,当然性能可能会有影响了。

     

     

     

     

     

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值