【问题标题】:Validation preventing command buttons验证阻止命令按钮
【发布时间】:2013-12-01 16:22:51
【问题描述】:

大家好,我有一些输入框,用户可以在其中输入详细信息并提交,这需要进行一些验证,而不是 null 等,这一切正常,但是如果用户有,我有一个导航按钮可以回家错误地来到这个页面,但是当用户按下这个按钮时,它也会调用验证并要求用户输入详细信息,这对于主页按钮是不好的,有什么办法我不能运行验证用户按下此按钮?这是一个primefaces命令按钮

这是代码,如果我使用链接,我可以很好地导航,但为了用户体验,我宁愿使用命令按钮

            <h:form>
                <p:growl id="growl" showDetail="true" sticky="true" />  
                <!--ajax messages working now -->

                <p:panel header="Enter details">  
                    <h:panelGrid columns="2">
                        <h:outputLabel value="#{bundle.CreateUserdetailsLabel_id}" for="id" />
                        <h:inputText id="id" value="#{userdetailsController.selected.id}" title="#{bundle.CreateUserdetailsTitle_id}" required="true" requiredMessage="#{bundle.CreateUserdetailsRequiredMessage_id}"/>
                        <h:outputLabel value="#{bundle.CreateUserdetailsLabel_username}" for="username" />

                        <h:inputText id="UserName" value="#{userdetailsController.selected.username}" title="#{bundle.CreateUserdetailsTitle_username}" required="true" 
                                     requiredMessage="Username is required"             
                                     label="UserName" >
                            <f:validator validatorId="richard.validator.UserNameValidator" />
                        </h:inputText>

                    </h:panelGrid>
                    <br />
                    <p:commandButton  action="#{userdetailsController.create}" value="#{bundle.CreateUserdetailsSaveLink}" update="growl"/>

                    <br />
                    <br />

                    <p:commandButton action="#{userdetailsController.prepareList}" value="#{bundle.CreateUserdetailsShowAllLink}" immediate="true"/>
                </p:panel>
                <br />
                <br />


                <!--
                Trying to use a command button to navigate however it is requiring the user enter details first and this is not acceptable so looking for a solution

                <p:commandButton action="{naviagation.buttonHome}" value="Home" icon ="ui-icon-home"  ajax="False"/>
                                        <p:commandButton action="{bundle.ListUserdetailsIndexLink}" value="List of all current records" icon ="ui-icon-person"  ajax="False"/>
                -->  

                <h:link outcome="/index" value="#{bundle.ListUserdetailsIndexLink}"/>

            </h:form>

谢谢

【问题讨论】:

    标签: jquery validation jsf primefaces


    【解决方案1】:

    您不应该为了页面到页面的导航而提交整个表单并触发 POST 请求。这不仅是错误的,而且对用户体验和 SEO 也不利。

    请改用&lt;p:button&gt;

    <p:button value="Home" outcome="/index" icon="ui-icon-home" />
    <p:button value="List of all current records" outcome="/list" icon="ui-icon-person" />
    

    如果你真的需要调用一个动作(我宁愿传递一个请求参数而不是让目标视图的&lt;f:event&gt;/&lt;f:viewAction&gt;对其执行业务逻辑),然后将process="@this"添加到@987654326 @ 以避免处理整个表单。请注意,immediate="true" 的用途完全不同,不应用于绕过整个表单处理的特定要求。

    【讨论】:

      【解决方案2】:

      找到解决办法

      immediate="true" 添加到命令按钮,该按钮应跳过处理所有没有immediate="true" 的输入字段 属性。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-28
      • 1970-01-01
      • 1970-01-01
      • 2018-01-04
      • 2021-02-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多