0

I am trying to figure out how to render a form after pressing a button that is part of a different form. I have successfully done this with datatables with no problem but I need to render input fields this time. I am using the latest version of JSF with netbeans and bootfaces.

There is a boolean member of the bean BookList called showAdd which should determine if the form is rendered and the method toggleShowAdd() changes this value to the opposite of its current value.

Starting from the button to view the form:

<h:commandButton action="#{bookList.toggleShowAdd}" 
                                 value="Add to Inventory">
                    <f:ajax render=":addForm" />
               </h:commandButton>
            </h:form>

            <h:form id="addForm" rendered="#{bookList.showAdd}">
                <b:row>
                    <b:column span="1">ISBN:</b:column>
                    <b:column span="1">
                        <h:inputText binding="#{isbn}" />
                    </b:column>
                </b:row>
                <b:row>
                    <b:column span="1">Title:</b:column>
                    <b:column span="1">
                        <h:inputText binding="#{title}" />
                    </b:column>
                </b:row>
                <b:row>
                    <b:column span="1">Author:</b:column>
                    <b:column span="1">
                        <h:inputText binding="#{author}"/>
                    </b:column>
                </b:row>
                <b:row>
                    <b:column span="1">Price:</b:column>
                    <b:column span="1">
                        <h:inputText binding="#{price}" />
                    </b:column>
                </b:row>
                <b:row>
                    <b:column span="1">
                        <h:commandButton value="Add" 
                                     action="#{bookList.addToInventory(isbn, title, author, price)}">
                            <f:ajax render="@form :inventoryview" />
                        </h:commandButton>
                    </b:column>
                </b:row>
            </h:form>
Tarik
  • 4,961
  • 3
  • 36
  • 67
Victoria Potvin
  • 127
  • 1
  • 11
  • What is the problem, please? Do not use multiple forms until/unless absolutely necessary. For this particular case see [this question/answer](http://stackoverflow.com/a/7807401/1391249). – Tiny Feb 24 '15 at 01:53
  • Your `` should not be part of your selective rendering logic. Use a panel of some sort instead – kolossus Feb 24 '15 at 04:40
  • Oh I understand now. I did not know that multiple forms was a no-no. – Victoria Potvin Feb 24 '15 at 18:17

0 Answers0