2016-04-06 4 views
-1

私は、リストのオブジェクトがマップのキーと同じかどうかをどのようにテストできるかを調べようとしています。Listに含まれるオブジェクトが、JSTLタグまたはStrutsタグを使用するJSPのMapのキーと同じであるかどうかを確認するにはどうすればよいですか?

Javaクラス:

private Map<String, List<Country>> continent; 
private List<Country> countries; 

国:

private String continentCode; 
private String countryCode; 
//other attributes 

大陸のMapキーがcontinentCodeです。

のjsp:

<s:iterator value=countries var=country> 
    <c:when test="${not empty continent[country.continentCode]}"> 
     <s:property value="country.continentCode"/> 
     <s:property value="country.countryCode"/> 
    </c:when> 
</s:iterator> 

私は<c:when>タグとわかりません。大陸地図にcontinentCodeが存在する場合、リストのCountryオブジェクトが表示されます。

+0

私はタグを忘れてしまったと考えています。しかしそれ以外は、私のコードが動作します。 – ERCK

答えて

0

を行うことができます。しかしそれ以外は、私のコードが動作します。

<s:iterator value=countries var=country> 
<c:choose>  
    <c:when test="${not empty continent[country.continentCode]}"> 
    <s:property value="country.continentCode"/> 
    <s:property value="country.countryCode"/> 
    </c:when> 
</c:choose> 

0

<c:choose>が欠落しているため、コードが機能しません。

<s:iterator value="countries" var="country"> 
    <c:choose> 
    <c:when test="${not empty continent[country.continentCode]}"> 
     <s:property value="%{#country.continentCode}"/> 
     <s:property value="%{#country.countryCode}"/> 
    </c:when> 
    </c:choose> 
</s:iterator> 

のStrutsタグを使用すると、私は<c:choose>タグを忘れてしまったと考えている

<s:iterator value="countries" var="country"> 
    <s:if test="continent[#country.continentCode] != null"> 
     <s:property value="%{#country.continentCode}"/> 
     <s:property value="%{#country.countryCode}"/> 
    </s:if>  
</s:iterator> 
+0

ローマに感謝します。国はすでに有効範囲に入っています。自分のコードにバグが見つかりました。私はタグを忘れました。 – ERCK

関連する問題