您好,我遇到以下代码问题。验证器工作正常,一切正常,我唯一的问题是不显示验证的错误消息。我错过了什么或问题是弹出窗口?
<rich:popupPanel id="popup" modal="true" height="280" width="200" resizeable="true" onmaskclick="#{rich:component('popup')}.hide()">
<f:facet name="header">
<h:outputText value="Simple popup panel" />
</f:facet>
<f:facet name="controls">
<h:outputLink value="#" onclick="#{rich:component('popup')}.hide(); return false;"> X </h:outputLink>
</f:facet>
<h:form id="newmssform">
<table class="position">
<tr>
<td>
<h:outputText class="output_text" value="New MSS Name:"/>
</td>
</tr>
<tr>
<td>
<h:inputText id="mssusernamefield" value="#{NetworkBean.newMss}">
<f:validator validatorId="NewMssValidator"/>
<f:attribute name="mssaddressfield" value="#{mssaddressfield}"/>
</h:inputText>
<h:message for="mssusernamefield" errorClass="errors"/>
</td>
</tr>
<tr>
<td>
<h:message for="mssusernamefield" errorClass="errors"/>
</td>
</tr>
<tr>
<td>
<h:outputText class="output_text" value="IP Address:"/>
</td>
</tr>
<tr>
<td>
<h:inputText id="mssaddressfield" value="#{NetworkBean.address}" binding="#{mssaddressfield}"/>
<h:message for="mssaddressfield" errorClass="errors"/>
</td>
</tr>
<tr>
<td>
<h:outputText class="output_text" value="User:"/>
</td>
</tr>
<tr>
<td>
<h:inputText id="mssuserfield" value="#{NetworkBean.mssUser}" />
</td>
</tr>
<tr>
<td>
<h:outputText class="output_text" value="Password:"/>
</td>
</tr>
<tr>
<td>
<h:inputSecret id="msspwdfield" value="#{NetworkBean.mssUserPass}" />
</td>
</tr>
<tr>
<td>
<a4j:commandButton style="border-radius: 5px; color: #FF6E00; font-weight: bold; font-size: 12px; margin-top: 5px;" value="Add New MSS"render="table,mss_table,oldIP" action="#{NetworkBean.addNewMss()}" />
</td>
</tr>
</table>
这是验证器:
public void validate(FacesContext fc, UIComponent uic, Object o) throws ValidatorException {
String mssName = o.toString();
UIInput addressComponent = (UIInput)uic.getAttributes().get("mssaddressfield");
String address = addressComponent.getSubmittedValue().toString();
UIInput userNameComponent = (UIInput) uic.getAttributes().get("mssaddressfield");
String userName = userNameComponent.getSubmittedValue().toString();
UIInput passwordComponent = (UIInput) uic.getAttributes().get("mssaddressfield");
String password = passwordComponent.getSubmittedValue().toString();
if(mssName.isEmpty() || address.isEmpty() || userName.isEmpty() || password.isEmpty()){
addressComponent.setValid(false);
userNameComponent.setValid(false);
passwordComponent.setValid(false);
throw new ValidatorException(
new FacesMessage("Error!"));
}
}
答案 0 :(得分:1)
根据我的预测,message
不按时投降
对于h:message
更改代码,如下例
<a4j:outputPanel ajaxRendered="true">
<h:message for="mssusernamefield" errorClass="errors"/>
<a4j:outputPanel>
这可能会对你有所帮助
答案 1 :(得分:0)
FacesMessage由两个字符串组成:摘要和详细信息。当您致电new FacesMessage("Error!")
时,您正在设置摘要。
h:message的默认行为是显示详细信息,但不显示摘要。您可以告诉它显示摘要:showSummary="true"
或提供FacesMessage中的详细信息:new FacesMessage("Error!", "Validation produced an error.")