【问题标题】:Checking size of collection that is a property of form bean in struts检查作为struts中form bean属性的集合的大小
【发布时间】:2012-04-23 17:04:05
【问题描述】:

我有一个集合,它是 struts 中 Form Bean 的一个属性。

我需要在 jsp 中检查该集合的大小。

在 C:IF 或 logic:equals 中,我没有找到如何指定表单名称和属性以及大小比较。

任何擅长struts的人。

【问题讨论】:

    标签: forms tags struts


    【解决方案1】:

    您可以像@Uchenna 建议的那样使用logic 标签库(由struts 框架提供)中的notEmpty 标签。

    或者,您可以直接使用JSTL中的c:if标签(带有EL ${}),后台logic:notEmpty也使用该标签。

    示例:

    <!-- This resolves to false even if myCollection is null -->
    <c:if test="${! empty myForm.myCollection}">
    
    </c:if>
    

    或者代替!,您也可以使用not 关键字(或运算符)。

    文档:

    【讨论】:

      【解决方案2】:

      当您转发到一个 jsp 时,表单名称将在该 jsp 的范围内。所以只需在jsp中引用表单名称,jsp就会看到。假设您在 struts-config.xml 中为表单类指定的名称是 MyFormName,列表属性名称是 myList:

      <logic:notEmpty name='MyFormName' property='myList'>
      
      
      </logic:notEmpty>
      

      如果这能解决您的问题,请告诉我。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-29
        • 1970-01-01
        • 1970-01-01
        • 2010-10-25
        • 2012-12-08
        • 1970-01-01
        • 2014-09-19
        相关资源
        最近更新 更多