1

I have a special row in my table for errors:

<tr>
    <td colspan="2"><p:message for="questionId" id="msgQuestion" /></td>
</tr>

How can I set this so the row is only displayed when there is an error?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
DD.
  • 21,498
  • 52
  • 157
  • 246
  • Is this a plain HTML table, hereby, it is neither a standard JSF component (like ``) nor a PrimeFaces component (like ``)? – Tiny Jul 01 '15 at 15:13
  • If rows inside the table are static (thus, `` is not wrapped inside `` and/or `` iterating components), then the same can be achieved using a component like `` and conditionally rendering `` inside it. – Tiny Jul 01 '15 at 15:24
  • I could use a panelGroup around the tr tag but I don't know what condition to render it. – DD. Jul 01 '15 at 15:26
  • i.e. how can I tell whether the p:message is displaying an error or not? – DD. Jul 01 '15 at 15:27
  • I have ever done something similar as stated by [this answer](http://stackoverflow.com/a/25187426/1391249). – Tiny Jul 01 '15 at 15:34

2 Answers2

0

In first place i will recommend not to use table to display layout elements

after that the ellement will apear even if the message is not present, if you are obliged to use it you can use som think like this in JS:

 <script type="text/javascript">
    window.onload = function() {
  hideTdMessage();
};
hideTdMessage(){
var message = document.getElementById(msgQuestion);
if(message){
   //the msg is present
}else{
   //the msg is not present 
}}
</script>

Or You can use your MBean to change the CSS class it's better than using JS.

But i will say that the best solution is not tu use the tabel.

Hope it helped

0

Use a JSF component and the property rendered

rendered="#{not empty facesContext.messageList}"