2016-11-09 16 views
1

入力があるフォームがあります。各入力は、別のhtmlページの表に表示されるデータのリストを返します。各入力には、そのデータを表示するテーブルがあります。私の仕事は、入力がユーザーによって入力されていない場合、データを表示しないことです。ここでjava:条件に応じてテーブルを表示または非表示にする

は、私は、テーブルを表示しないためにループの外に行くためにブレークを使用しています私のコード

<!-- Country Table--> 
        <%for(int i = 0; i < countryList.length;i++){ 
         if(countryList.length == 0) 

          break; 
         %> 
        <div class="box" align="center"> 
         <table name="tab" align="center" class="gridtable"> 
          <thead > 
           <tr> 
            <th style="width: 50%" scope="col">Entity Watch List Key</th> 
            <th style="width: 50%" scope="col">Watch List Name</th> 
           </tr> 
          </thead> 
          <tbody> 

           <tr> 
           <td style="width: 50%"><%out.println((String) (countryList[i].getEntityWatchListKey()));%></td> 
           <td style="width: 50%"><%out.println((String) (countryList[i].getEntityName()));%></td> 
           </tr> 


          </tbody> 
         </table> 
        </div> 
         <%}%> 

あり、それは本当ですか?

答えて

0

さらにループのためにあなたが現在持っているあなたは、forループ、

if(countryList.length != 0) 

または

if(countryList.length > 0) 

前に、この条件を使用することができ、その後、あなたがブレーク条件を使用する必要はありません、

配列の長さが0の場合、この条件は< countryList.lengthは0 <になり、それは0になります私は失敗するので、あなたのforループは入力されません。あなたの現在の条件がif(countryList.length == 0)にはアクセスされません。

0

あなたが行ない、テーブルを繰り返す必要は良い練習のためにあなたのコード

<div class="box" align="center"> 
<table name="tab" align="center" class="gridtable"> 
    <thead > 
     <tr> 
      <th style="width: 50%" scope="col">Entity Watch List Key</th> 
      <th style="width: 50%" scope="col">Watch List Name</th> 
     </tr> 
    </thead> 
    <tbody> 

<%for(int i = 0; i < countryList.length;i++){ 
     if(countryList.length > 0) %> 
      <tr> 
      <td style="width: 50%"><%out.println((String) (countryList[i].getEntityWatchListKey()));%></td> 
      <td style="width: 50%"><%out.println((String) (countryList[i].getEntityName()));%></td> 
      </tr> 

<%}%> 
    </tbody> 
</table> 
</div> 

を変更してください。

関連する問題