Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Having problem with Add/Remove rows dynamically...

 
Srinivas Kasani
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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}" />
</h:selectOneMenu>

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

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.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic