<h:inputText> doesn't seem to work within <ui:repeat>, only the last entry is submitted

拈花ヽ惹草 提交于 2019-12-01 11:31:08
BalusC

It's caused because you're (re)creating the list in the getter method behind <ui:repeat value>. This method is invoked during every iteration round. So, every next iteration will basically trash the values set during the previous iteration. In the action method, you end up with the list as created during the last iteration round. That's why the last entry seems to work fine.

This approach is indeed absolutely not right. You should not be performing business logic in getter methods at all. Make the list a property and fill it only once during bean's (post)construction.

@ManagedBean(name = "genproducts")
@ViewScoped
public class Genproducts{

    private List<Product> list;

    @PostConstruct
    public void init() throws SQLException {
        list = new ArrayList<>();
        // ...
    }

    public List<Product> getList() {
        return list;
    }

} 

Which is to be referenced as

<ui:repeat value="#{genproducts.list}" var="itemsBuying">

See also

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