我的表中有一个特殊的行用于错误:
<tr>
<td colspan="2"><p:message for="questionId" id="msgQuestion" /></td>
</tr>
如何设置此行,以便仅在出现错误时显示该行?
我的表中有一个特殊的行用于错误:
<tr>
<td colspan="2"><p:message for="questionId" id="msgQuestion" /></td>
</tr>
如何设置此行,以便仅在出现错误时显示该行?
首先,我建议不要使用表格来显示布局元素
之后,即使消息不存在,元素也会出现,如果你必须使用它,你可以在 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 更好。
但我会说最好的解决方案不是你使用表格。
希望它有所帮助
使用 JSF 组件和呈现的属性
rendered="#{not empty facesContext.messageList}"