How to Dynamically adding fields in JSF?

假装没事ソ 提交于 2019-12-11 00:18:17

问题


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


回答1:


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:

  • How to dynamically add new row to table? - detailed answer to similar question
  • Using Datatables - shows step by step how to use datatables in JSF 1.x.
  • CRUD datatable using @ViewScoped - simple example of JSF 2.0 CRUD


来源:https://stackoverflow.com/questions/3640635/how-to-dynamically-adding-fields-in-jsf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!