0

您好,我对以下代码有疑问。验证器工作正常,一切都很好,我唯一的问题是验证的错误消息没有显示。我是否遗漏了什么或问题出在弹出窗口上?

<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!")); 
        }

    }
4

2 回答 2

1

As my prediction your message not rerender ontime
for h:message change code like below example

<a4j:outputPanel ajaxRendered="true">
    <h:message for="mssusernamefield" errorClass="errors"/>
<a4j:outputPanel>

this may help you

于 2013-07-16T09:28:38.890 回答
0

FacesMessage由两个字符串组成:摘要和详细信息。当您打电话时,new FacesMessage("Error!")您正在设置摘要。

h:message的默认行为是显示详细信息,但不显示摘要。您可以告诉它显示摘要:showSummary="true"或在 FacesMessage 中提供详细信息:new FacesMessage("Error!", "Validation produced an error.")

于 2013-07-16T09:27:04.963 回答