0

I have a form with several fields and there is a block with two required fields and a search button. What i want is when i click on search button i want to ignore the form validations and that the two fields values to be set in the bean, but this doesnt happen. How should I apply the values?

EDIT: I have more required fields in the view, that in this case i want ignore.

<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"/>
Jorge
  • 31
  • 4
  • I posted the title of your question in Google and found http://stackoverflow.com/questions/6062923/how-to-skip-validation-when-a-specific-button-is-clicked. So the difference is that you only want it for two fields? – Kukeltje Jul 29 '16 at 12:09
  • I have more fields in my view that are required. In this case, the action of button is not executed. Solutions? – Jorge Jul 29 '16 at 13:03
  • 2
    Possible duplicate of [How to let validation depend on the pressed button?](http://stackoverflow.com/questions/8370675/how-to-let-validation-depend-on-the-pressed-button) – Kukeltje Jul 29 '16 at 13:29

1 Answers1

0

Remove immediate="true" from <p:commandButton />.

From this article:

... When immediate is set to true on an Command component, the action is invoked in the Apply Request Values phase ...

... so your model values will not be updated at all.

irieill
  • 1,203
  • 10
  • 32
  • Ok, but i have more fields in my view that are required. In this case, the action of button is not executed. Solutions? – Jorge Jul 29 '16 at 12:57
  • @Jorge Even if you have more fields with `required="true"`, as long as you keep `process="@this, field1, field2"` on your `` they will be ignored. But just for completeness, please update your question with these additional fields. Maybe they are configured in some way that prevents the `actionListener` from execution. – irieill Jul 29 '16 at 13:30
  • @Jorge Are there any updates? Did my answer help you? – irieill Aug 12 '16 at 09:05
  • Yes, and I found fragments that not helped me and was the cause of the problem! – Jorge Aug 12 '16 at 15:53