Submit a form without validitating required fields primefaces

I want to have a form with JSF (Primefaces) to have a required field (the username is this example) to be required when saved. Also you can add books to every user, a user can have 0 ... n books. If you add a new book, it is required to give it an author and a name.

I tried it with the code below and already tried many ways of the Partial Processing of Primefaces. However, it is not working correctly. Sometimes I have to enter the required username to add a book or save it not working at all. Is there a way, to only check the required username on save and ignore the required author and bookname?

This is the code for the example:

        <h:form>
            <p:outputPanel id=„userdetails“>
                <p:inputText id="name" value="#{bean.name}" />
            </p:outputPanel>

            <p:inputText id="txt_title" value="#{createBookBean.book.title}"
                required="true" />
            <p:inputText id="txt_author" required="true"
                value="#{createBookBean.book.author}" />

            <p:commandButton value="Reset" type="reset" />
            <p:commandButton id="btn_add" value="Add"
                update="books msgs @parent" action="#{createBookBean.reinit}">
                <p:collector value="#{createBookBean.book}"
                    addTo="#{createBookBean.books}" />
            </p:commandButton>
            <p:outputPanel id="books">
                <p:dataTable id="booksTable" value="#{createBookBean.books}"
                    var="book">
                    <h:outputText value="#{book.title}" />

                    <h:outputText value="#{book.author}" />

                    <p:column>
                        <p:commandLink value="Remove" update=":form:books"
                            process=":form:books">
                            <p:collector value="#{book}"
                                removeFrom="#{createBookBean.books}" />
                        </p:commandLink>
                    </p:column>
                </p:dataTable>
            </p:outputPanel>

            <p:commandButton value="Save" update="msgs" process="@form"
                action="#{bean.save()}"></p:commandButton>  // button to save, and ignore required bookname
        </h:form>

// button to save, and ignore required bookname

Upvotes: 1

Views: 4516

Answers (1)

Vasil Lukach
Vasil Lukach

Reputation: 3748

For that purpose you can use immediate attribute of commandButton:

<p:commandButton value="Save" update="msgs" process="@form"
    action="#{bean.save()}" immediate="true" />

Upvotes: 3

Related Questions