如何验证 Struts2 if 标签中的 HashSet 大小是否大于零?

how to validate HashSet size greather than zero in Struts2 if tag?

我正在使用 Struts2 并想使用 Struts2 if 标签检查 HashSet 属性 大小是否大于零。

struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.devMode" value="true" />

    <package name="bundle" extends="struts-default" namespace="/">

      <action name="process" 
            class="sample.action.Process" 
            method="execute">
            <interceptor-ref name="defaultStack" />
            <result name="success">/jsp/result.jsp</result>
      </action>

    </package>  
</struts>

POJO

package sample.pojo;
public class Customer{

    private Integer id;
    String name;
    int age;

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }

}

操作Class

package sample.action;


import java.util.HashSet;
import java.util.Set;

import sample.pojo.Customer;

import com.opensymphony.xwork2.ActionSupport;

public class Process extends ActionSupport 
{
    private Set<Customer> result = new HashSet<Customer>();

    public String execute() 
    {
        Customer cust1 = new Customer();
        cust1.setId(1);
        cust1.setAge(59);
        cust1.setName("Subramanian");
        result.add(cust1);

        return SUCCESS;
    }

    public Set<Customer> getResult() {
        return result;
    }

    public void setResult(Set<Customer> result) {
        this.result = result;
    }
}   

VIEW

<!DOCTYPE html>
<html>
<head>
<%@ taglib prefix="s" uri="/struts-tags"%>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=8;" />
<title>Welcome Page</title>
</head>
<body>

<s:if test="*<syntax>*">
java.util.HashSet size is <s:property value="result.size"/> 
</s:if>
<s:else>
java.util.HashSet size is empty!
</s:else>

</body>
</html>

请帮助 Struts2 如果要在视图中使用标记语法。谢谢!

下面的代码片段对我有用

<s:if test="%{mySet.size()>0}">