• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Having problem with Add/Remove rows dynamically...

Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having problem doing Add/Remove rows dynamically.
I'm having a row which has list of dropdown and text boxes. This row is part of rich:datatable. At the end of the row, we provide an option to either add a similar row or delete the row. When user clicks on the Add button, in the java code I'm just incrementing the counter and rerendering the rich:datatable again.
jsf code snippet..
<rich:dataTable value="#{coreService.dataList}" var="counter" id="list">
<h:selectOneMenu value="#{coreService.selectName}" rerender="true">
<f:selectItems value="#{coreSerice.listOfNames}" />

<a4j:commandButton value="+" action="#{coreService.addARow}" reRender="list"/>

The problem is, when we submit the form and when we have mulitple rows, I'm not able to read all the selected dropdown values. It is getting overwritten and only the last dropdown value I'm able to capture in the backing bean. Can anyone provide some insight on how to solve this problem.
Saloon Keeper
Posts: 25841
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is this "rerender="true"" thing?

I think you're not taking advantage of the row-tracking mechanism on the datamodel. In fact, I strongly suspect that you're doing things the hard way and attempting to actively pull the value of the selection in the action method.

JSF doesn't work that way. When you have a dataTable DataModel, the model's rows are updated when you perform input operations (such as dropdown selection) on the row items. Ahhh. yes. but you're not, are you? You made the control target be the backing bean itself, not a row! Of course you're only going to get the last value! You can't cram 5 values into a 1-value object!

Try this instead:

Make sure that the row object contains a "selectName" property.

Now you can get the values from the selectName properties on the row objects by enumerating the wrapped data (rows) of the dataList object.
    Bookmark Topic Watch Topic
  • New Topic