1 2 3 Previous Next 37 Replies Latest reply on Feb 1, 2010 11:29 AM by waq

    adding a new row

      I have a form for courses registeration. Form contains different components like text fields. There is another field called Topics. Now i want to provide the user with an option that he can add more than one topic. So is there any way that i can add a new row with an empty text field?

       

      One way i know is by using javascript but in that case we are not sure how many backing mean property is requried for the Topics field, since user can select as many topics as he wants.

        • 1. Re: adding a new row
          ilya_shaikovsky
          http://in.relation.to/11633.lace - this case contains not the concrete code for yours case but I think clearly shows the way. In the thread tabs added dynamically on search, and in your case all is even simplier - just to add one more input on clicking some add button.
          • 2. Re: adding a new row
            is there any other way instead of using JSTL?
            • 3. Re: adding a new row
              elf

              In case of "another field called Topics"  is table, may be it will be good to:

              1. create ADD button on UI

              2. call some bean action clicking this button

              3. add new Topic class object to bean array (binded to UI table)

              4. refresh table on complete this action

              • 4. Re: adding a new row

                ok i did as:

                .XHTML

                 

                <

                 

                a4j:outputPanel id="topics_panel">

                 

                <a4j:region id="topic_region">

                 

                <h:dataTable value="#{regesterCourse.topicList}" var="top">

                 

                <h:column>

                 

                <h:inputText id="course_topics"

                 

                value="#{top.topic}" size="20" />

                 

                </h:column>

                 

                </h:dataTable>

                 

                <a4j:commandButton value="A" reRender="topics_panel"

                 

                action="#{regesterCourse.addNewRow}"/>

                 

                </a4j:region>

                 

                <a4j:status for="topic_region" startText="Wait" stopText=""/>

                 

                </a4j:outputPanel>

                 

                .JAVA

                public

                 

                 

                void addNewRow() {

                 

                topicList.add(new TopicList(""));

                }

                //end addNewRow()

                 

                but it adds only one row, even button calls the action everytime i hit it.

                • 5. Re: adding a new row
                  any suggestions...???
                  • 6. Re: adding a new row
                    nbelaevski
                    What is bean scope?
                    • 7. Re: adding a new row
                      its request
                      • 8. Re: adding a new row
                        nbelaevski
                        Use scope with longer lifetime, e.g. session or conversation.
                        • 9. Re: adding a new row
                          can t:saveState work for it? But why it still calls action on every button hit?
                          • 10. Re: adding a new row

                            ok i used a4j:keepAlive and it works for me but when i press submit button it thorws java.lang.IllegalStateException.

                            After debugging i came to know that exception is comming from the following .JAVA statement:

                             

                            HttpSession session = (HttpSession)

                            context.getExternalContext().getSession(false);

                            • 11. Re: adding a new row

                              any solution on this? i found that the issue occur because session got invalidated. but can't able to find the solution for this.

                               

                              Moreover i am trying to provide a delete functionality to the user which allows the user to delete the current row. It works fine but it always delete the last row.

                               

                              <

                               

                              rich:dataTable value="#{regesterCourse.topicList}" var="top"

                               

                              rowKeyVar="row">

                               

                              <rich:column>

                               

                              <h:inputText id="topic_list_fld" value="#{top.topic}"/>

                               

                              <a4j:commandButton value="Delete" reRender="topic_panel"

                               

                              action="#{regesterCourse.removeTopicRow}">

                               

                              <a4j:actionparam value="#{row}"

                               

                              assignTo="#{regesterCourse.topicIndex}"/>

                               

                              </a4j:commandButton>

                               

                              </rich:column>

                               

                              <rich:column>

                               

                              <h:outputText value="#{row}"/>

                               

                              </rich:column>

                               

                              </rich:dataTable>

                               

                              public

                               

                               

                              void removeTopicRow() {

                              System.

                              out.println("index is ......." + this.getTopicIndex());  //THIS STATEMENT ALWAYS RETURN 0

                               

                              topicList.remove(this.getTopicIndex());

                              }

                              //end removeTopicRow()

                              • 12. Re: adding a new row
                                any suggestions...???
                                • 13. Re: adding a new row

                                  waq wrote:

                                   

                                  Moreover i am trying to provide a delete functionality to the user which allows the user to delete the current row. It works fine but it always delete the last row.

                                  I beg your pardon. it always delete the first row.

                                  Please do help me out on this issue. I've been googling since yesterday but not come up with any solution yet.

                                  • 14. Re: adding a new row
                                    nbelaevski
                                    Have you checked if "#{regesterCourse.topicIndex}" expression has ever been updated?
                                    1 2 3 Previous Next