aspose file tools*
The moose likes JSF and the fly likes Having problem with Add/Remove rows dynamically... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Having problem with Add/Remove rows dynamically..." Watch "Having problem with Add/Remove rows dynamically..." New topic
Author

Having problem with Add/Remove rows dynamically...

Srinivas Kasani
Greenhorn

Joined: Sep 26, 2008
Posts: 22
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

Joined: Jun 25, 2001
Posts: 16012
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Having problem with Add/Remove rows dynamically...