1

我的表中有一个特殊的行用于错误:

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

如何设置此行,以便仅在出现错误时显示该行?

4

2 回答 2

0

首先,我建议不要使用表格来显示布局元素

之后,即使消息不存在,元素也会出现,如果你必须使用它,你可以在 JS 中使用 som think like this:

 <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>

或者您可以使用 MBean 更改 CSS 类,这比使用 JS 更好。

但我会说最好的解决方案不是你使用表格。

希望它有所帮助

于 2015-07-01T15:38:35.587 回答
0

使用 JSF 组件和呈现的属性

rendered="#{not empty facesContext.messageList}"
于 2018-05-21T22:30:27.913 回答