1

JSTLを使用してBeanクラスから値を取得しています。Beanクラスから取得する値は、java.util.Mapになります。以下のコードで値を取得することに成功しています:

<c:forEach items="${bean.map}" var="item">  
  <c:out value="${item.key}"/> = <c:out value="${item.value}"/><br/>  
</c:forEach> 

キーと値のペアを取得した後、4行7列のテーブルを作成する必要があります。地図:

map.put(2, true);
map.put(18, true);

マップのキーは1〜28で、値はTRUEまたはFALSEになります。

キーが2で、値がTRUEの場合、テーブルの(1,2)にチェックマークを付ける必要があります。つまり、1行2列目です。

同様に、キーが18の場合、表の(3,4)にチェックマークを付ける必要があります。

         <table border="1" width="100%">
         <tr>
         <th>1</th>
         <th>2</th>
         <th>3</th>
         <th>4</th>
         <th>5</th>
         <th>6</th>
         <th>7</th>
        </tr>
        <c:forEach items="${bean.map}" var="item" >
        <tr>
       <td><c:out value="${item.value}"/></td>
        </tr>
        </c:forEach>
        </table>

私はJSTLのみを使用するように制限されており、JSTLを初めて使用するため、さらに先に進む方法がわかりません。生活を楽にするjavascriptorjqueryの使用は許可されていません。

さらに先に進むための提案をお願いします。どんな助けでもかなりのものになります。

4

1 に答える 1

0

ビューでJSTLを使用するのではなく、コントローラーでJavaコードを使用してエントリを行に分割します。可能ですが、Java で行うとすべてが簡単になります。

また、マップを使用して 1 から 28 までのキーを含めるのは少し奇妙です。28個のブール値のリストを使用しないのはなぜですか?

/**
 * Returns a list of 4 lists of booleans (assuming the map contains 28 entries going 
 * from 1 to 28). Each of the 4 lists contaisn 7 booleans.
 */
public List<List<Boolean>> partition(Map<Integer, Boolean> map) {
    List<List<Boolean>> result = new ArrayList<List<Boolean>>(4);
    List<Boolean> currentList = null;
    for (int i = 1; i <= 28; i++) {
        if ((i - 1) % 7 == 0) {
            currentList = new ArrayList<Boolean>(7);
            result.add(currentList);
        }
        currentList.add(map.get(i));
    }
    return result;
}

そしてあなたのJSPで:

<table border="1" width="100%">
    <tr>
         <th>1</th>
         <th>2</th>
         <th>3</th>
         <th>4</th>
         <th>5</th>
         <th>6</th>
         <th>7</th>
    </tr>
    <c:forEach items="${rows}" var="row">
        <tr>
            <c:forEach items="row" var="value">            
                <td><c:out value="${value}"/></td>
            </c:forEach>
        </tr>
    </c:forEach>
</table>
于 2013-01-23T14:30:58.570 に答える