(Struts→JSF移行)処理振り分けの時に閉じタグがらみのエラーが出る例[プログラミング]
(2017-07-18 12:28:00) by shinoda


< ページ移動: 1 2 >

例えば、tr タグの高さを if 文で切り分けているところ。

Struts JSP
<logic:equal name="hoge1" property="flg1" value="true">
<tr height="30">
</logic:equal>
<logic:notEqual name="hoge1" property="flg1" value="true">
<tr height="50">
</logic:notEqual>
  <td>
    <table>
     <tr>
       <td>hogehoge1</td>
    </tr>
  <logic:notEqual name="hoge1" property="flg1" value="true">
    <tr>
      <td>hogehoge2</td>
    </tr>
  </logic:notEqual>
    </table>
  </td>
</tr>

Struts であればこんな感じで書かれている処理。
flg1 が真(True)ではなかった時は入れ子になった table の高さが(hogehoge2 を出力する分だけ)高くなるので、その外側の tr タグの height 属性を 50にしているんだね(True の場合は 30)

これを単純に、

JSF XHTML
<c:if test="#{form.flg1}">
<tr height="30">
</c:if>
<c:if test="#{!form.flg1}">
<tr height="50">
</c:if>
  <td>
    <table>
     <tr>
       <td>hogehoge1</td>
    </tr>
  <c:if test="#{!form.flg1}">
    <tr>
      <td>hogehoge2</td>
    </tr>
  </c:if>
    </table>
  </td>
</tr>

このように書くと、xhtml 的には、(<c:if>タグで分岐していることは無視され)<tr>タグが2つ(height="30" のものと、"50" のもの)あるのに、閉じタグ(</tr>)の数がひとつ足りないので、

Errir Traced[line: 323] The element type "tr" must be terminated by the matching end-tag "</tr>".
 
というエラーになる。厳密やねえ、xhtml。

なので、この場合は、以下のように </tr> までの部分をひとつにまとめて if 文による分岐を行なってやる必要がある。
ちょっと二重コーディングになって無駄な気もするけど・・・

JSF XHTML
<c:if test="#{form.flg1}">
<tr height="30">
  <td>
    <table>
      <tr>
        <td>hogehoge1</td>
      </tr>
    </table>
  </td>
</tr>
</c:if>
<c:if test="#{!form.flg1}">
<tr height="50">
  <td>
    <table>
      <tr>
        <td>hogehoge1</td>
      </tr>
      <tr>
        <td>hogehoge2</td>
      </tr>
    </table>
  </td>
</tr>
</c:if>

< ページ移動: 1 2 >


コメント投稿
次の記事へ >
< 前の記事へ
TOPへ戻る

Powered by
MT4i 3.0.8