【问题标题】:JSF Message Validation not workingJSF 消息验证不起作用
【发布时间】:2013-12-08 14:01:07
【问题描述】:

大家好,我想实现不同的输入字段,如果有些人在文本字段中没有输入任何内容,请直接从文本字段中显示一条消息。如果输入正确,则显示一个对话框。

我正在使用 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>

【问题讨论】:

  • “不工作”是什么意思?
  • 如果我没有在文本字段中输入任何内容并单击按钮,则不会显示任何消息。

标签: jsf jsf-2 primefaces


【解决方案1】:

p:commandButton 默认使用 ajax,因此您必须更新面板或添加属性 ajax=false 以让页面刷新并显示消息

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2012-08-29
  • 1970-01-01
  • 2014-05-29
  • 2013-11-25
  • 2014-08-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多