私は<h:messages>JSF で要素を使用することにあまり慣れていません。私がやろうとしているのは、それを使用して、バッキング Bean のメソッドによって生成されるさまざまな重大度のグローバル メッセージのリストを表示することです。メッセージを に入れることFacesContextはそれほど問題ではなく、私のコードは次の行に沿っています。
FacesMessage message;
FacesContext context =
FacesContext.getCurrentInstance();
message = new FacesMessage(
FacesMessage.SEVERITY_INFO,
"test message summary 1",
"test message detail 1");
context.addMessage(null, message);
message = new FacesMessage(
FacesMessage.SEVERITY_WARN,
"test message summary 2",
"test message detail 2");
context.addMessage(null, message);
message = new FacesMessage(
FacesMessage.SEVERITY_ERROR,
"test message summary 3",
"test message detail 3");
context.addMessage(null, message);
// add more messages...
それはすべてうまくいきます。私の問題は、<h:messages>タグの出力がページ上で見栄えがするようにすることです。私のJSPファイルの関連部分は次のとおりです。
<h:panelGrid border="1" columns="1" id="messagesPanelGrid">
<h:messages
id="messagesOutput"
showSummary="true"
showDetail="true"
layout="table"
infoClass="info-message"
warnClass="warn-message"
errorClass="error-message"
fatalClass="fatal-message"
globalOnly="true" />
</h:panelGrid>
これは一貫して、ページ上ではがらくたのように見えます。スタイル クラスを定義するために、外部の CSS スタイルシートを使用しています。を使用してみましlayout="list"たが、リスト項目がページ全体に広がり、ブロックのスタイルが悪く見えるため、に切り替えましたlayout="table"。スタイルを適用できるブロック レベルの要素がいくつか<h:messages>あるように、内側をフレームに収めました。<h:panelGrid>見た目はまだ特にいい感じではありません。
私が今得ているもの:
<table border="1" id="myForm:messagesOutput">
<tr><td class="error-message"><span>no port name match Could not match reported port name XXXX to a known port for vessel VESSEL A</span></td></tr>
<tr><td class="error-message"><span>no port name match Could not match reported port name YYYY to a known port for vessel VESSEL B</span></td></tr>
<tr><td class="error-message"><span>no port name match Could not match reported port name YYYY to a known port for vessel VESSEL C</span></td></tr>
<tr><td class="error-message"><span>no port name match Could not match reported port name ZZZZ to a known port for vessel VESSEL D</span></td></tr>
<tr><td class="warn-message"><span>arrival date missing No arrival date provided for vessel VESSEL B</span></td></tr>
</table>
私が取得しようとしているもの:
<table border="1" id="myForm:messagesOutput" class="myMessagesTableClass">
<thead><tr"><td>SUMMARY</td><td>DETAIL</td></tr></thead>
<tr><td class="error-message-summary"><span>no port name match</span></td><td class="error-message-detail"><span>Could not match reported port name XXXX to a known port for vessel VESSEL A</span></td></tr>
<tr><td class="error-message-summary"><span>no port name match</span></td><td class="error-message-detail"><span>Could not match reported port name YYYY to a known port for vessel VESSEL B</span></td></tr>
<tr><td class="error-message-summary"><span>no port name match</span></td><td class="error-message-detail"><span>Could not match reported port name YYYY to a known port for vessel VESSEL C</span></td></tr>
<tr><td class="error-message-summary"><span>no port name match</span></td><td class="error-message-detail"><span>Could not match reported port name ZZZZ to a known port for vessel VESSEL D</span></td></tr>
<tr><td class="warn-message-summary"><span>arrival date missing</span></td><td class="warn-message-detail"><span>No arrival date provided for vessel VESSEL B</span></td></tr>
</table>
- メッセージは表形式のままですが、「概要」と「詳細」は別の列に表示されます
- 生成されたテーブルには、直接割り当てられた CSS クラスがあります
- メッセージの「要約」部分と「詳細」部分には、別々のスタイル クラスがあります。
- あると便利: テーブルのヘッダー行
スクリーンショット:

誰かが<h:messages>タグを扱っていて、これを達成する方法についていくつかのアイデアを持っていますか?
この質問に関係があるかどうかはわかりませんが、MyFaces 1.2 を使用しています。現時点では 2.x にアップグレードできません。