Inserting multiple datas in 1 entity in a page

前端 未结 1 847
旧巷少年郎
旧巷少年郎 2020-12-22 11:35

i have a CRUD generated create form:

1条回答
  •  南笙
    南笙 (楼主)
    2020-12-22 12:18

    You can't send data from many forms in a single request using JSF components, you should serialize all the data and send it manually. It would be better to have a List and every time you click in the button it will create a new item on the list and update an UIContainer that will display the items of the list.

    This would be a start example of the above:

    @ManagedBean
    @ViewScoped
    public class ItemBean {
        private List lstItem;
    
        public ItemBean() {
            lstItem = new ArrayList();
            addItem();
        }
        //getters and setter...
    
        public void addItem() {
            lstItem.add(new Item());
        }
    
        public void saveData() {
            //you can inject the service as an EJB or however you think would be better...
            ItemService itemService = new ItemService();
            itemService.save(lstItem);
        }
    }
    

    JSF code ( content only):

    
        
            
                Enter item name
                
                
    Enter item description

    0 讨论(0)
提交回复
热议问题