tags:

views:

85

answers:

1

HI All,

I am desperately looking for the assistance on adding and removing the fields and rows using JSF. I am using ICE Faces for the rich UI look. The following is my problem:

  1. I have to add one text box and two buttons (+) and (-) in a row.
  2. When user clicks on the + button, one new row should be added with the above components.
  3. When user clicks on the - button, the corresponding row should be removed from the display.

I am able to add the individual components like text box and remove it. But, here my challenging point is to add and remove as a row. How would I remove that specific row (instance) from the UI View Root.

I have tried several times, but till now I could not find a solution. Please suggest me the possible solutions.

Thanks in advance, Krishna

+2  A: 

Rather use a h:dataTable (or the IceFaces equivalent ice:dataTable) which is backed by a List<Data> contining objects which each represents the data of a single row. On Add just add a new Data item to the list. On Remove just remove the selected Data item from the list.

See also:

BalusC
HI BalusC,Thank you for the reply. Do you mean that I can add any component in the DataTable row itself? Do you have any sample code or API for the backing bean? That would be helpful.I will try that and let you know if I have any doubts.Thanks,Krishna
Krishna
No, you don't add whole components. That's unnecessarily overcomplicated. Just add a new item to the list/datamodel which the `dataTable` is using. The `datatable` will then display it as a new row. I've updated the answer with some useful links.
BalusC
Thank you BalusC
Krishna
You'r welcome. Don't forget to mark the answer accepted if it helped. See also http://stackoverflow.com/faq.
BalusC