2013-12-08 81 views
0

嗨夥計我想實現不同的輸入字段,如果有些在文本字段中沒有放置任何內容,請在文本字段中顯示一條消息。如果輸入正確,則顯示一個對話框。JSF消息驗證不起作用

我使用primefaces 3.5和JSF 2.1

謝謝您的幫助。

reg.xhtml

<ui:composition template="/META-INF/templates/templateLogin.xhtml"> 

     <ui:define name="title"> 
       <h:outputText value="Register"/> 
     </ui:define> 

     <ui:define name="content">   
      <h:form id="regiForm"> 

       <p:panelGrid >     
        <p:row style="height:20%"> 
         <p:column><h:outputLabel value="#{msg['regi_firstname']}" /></p:column>  
         <p:column> 
          <p:inputText style="width:350px" id="firstname" 
            value="#{regiBean.firstname}" required="true" requiredMessage="#{msg['regi_firstname_error']}" />         
         </p:column>  
         <p:column><p:message for="firstname"/></p:column>  
        </p:row> 




        <p:row style="height:20%">   
         <p:column><h:outputText/> </p:column>  
         <p:column> 
          <p:commandButton style="width:350px" type="submit" actionListener="#{regiBean.showDialog}" 
             value="#{msg['regi_button']}" /> 
         </p:column> 
         <p:column></p:column> 
        </p:row> 

       </p:panelGrid> 
       <p:dialog id="dialog" header="#{msg['regi_dialog_header']}" widgetVar="myDialog" position="center center" > 
         <h:outputText value="#{msg['regi_dialog']}" /> 
       </p:dialog> 
      </h:form> 

     </ui:define> 
    </ui:composition> 
</h:body> 
</f:view> 
</html> 
+0

「不工作」是什麼意思? – kolossus

+0

如果我沒有在文本字段中填寫任何內容並單擊按鈕,則不顯示任何消息。 – bvb1909

回答

1

號碼:的commandButton使用AJAX爲默認值,所以你必須更新面板或添加屬性的ajax = false來讓頁面刷新,並顯示消息

+1

添加一些代碼到您的答案將包括其質量 – kolossus

+0

如果我添加更新=「regiForm」消息是shon,但該方法沒有被調用,該方法也。 – bvb1909