2016-07-29 100 views
0

我有一个包含多个字段的表单,并且有一个包含两个必填字段和搜索按钮的块。 我想要的是,当我点击搜索按钮时,我想忽略表单验证,并且两个字段的值在bean中设置,但这不会发生。 我应该如何应用这些值?单击特定按钮并设置特定值时跳过验证

编辑:我在视图中有更多必填字段,在这种情况下,我想忽略。

<p:inputMask id="field1" mask="9999" styleClass="marginLeft input smaller" 
           requiredMessage="#{label.msg_requiredFields}" 
           required="true" value="#{cc.attrs.cena.field.cp4Offline}"/> 

        <p:inputMask id="field2" mask="999" 
           requiredMessage="#{label.msg_requiredFields}" 
           required="true" styleClass="input smallest" 
           value="#{cc.attrs.cena.field.cp3Offline}"/> 

        <p:commandButton id="pesquisarId" styleClass="marginLeft" icon="ui-icon-search" 
            actionListener="#{pesquisarMorada.pesquisar(cc.attrs.cena)}" 
       update="resultPesquisaPanelId" process="@this field1 field2" immediate="true"/> 
+0

我发布你的问题的标题在谷歌和发现http://stackoverflow.com/questions/6062923/how-to-skip-validation-when-a-specific-button-is-clicked。所以区别在于你只需要两个字段? – Kukeltje

+0

我在我看来有更多的字段是必需的。在这种情况下,按钮的动作不会被执行。解决方案? – Jorge

+2

的可能的复制[如何让验证取决于按下的按钮?](http://stackoverflow.com/questions/8370675/how-to-let-validation-depend-on-the-pressed-button) – Kukeltje

回答

0

<p:commandButton />删除immediate="true"

从这个article

...当直接设置为true的命令组件上,行动调用的应用请求值阶段...

...所以你的模型值将不会被更新。

+0

好,但我认为需要更多的领域。在这种情况下,按钮的动作不会被执行。 解决方案? – Jorge

+0

@Jorge即使你有更多的字段需要使用'required =“true”',只要你在''上保留'process =“@ this,field1,field2”',它们将被忽略。但为了完整性,请用这些附加字段更新您的问题。也许它们是以某种方式配置的,以防止执行'actionListener'。 – irieill

+0

@Jorge有没有更新?我的回答对你有帮助吗? – irieill

相关问题