Form submit in conditionally rendered component is not processed

大城市里の小女人 提交于 2019-11-26 23:19:13
BalusC

Your concrete problem is caused by 2 facts:

  1. When JSF needs to decode a form submit action, it also checks if the component is rendered or not (as safeguard against hacked/tampered requests).
  2. Request scoped beans are recreated on every HTTP request (an ajax request counts also as one request!).

In your specific case, the rendered condition has evaluated false while JSF needs to decode the form submit action and therefore the non-rendered input/command components are never processed.

Putting the bean in view scope should fix it. Below example assumes JSF 2.x.

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped

And below example assumes JSF 2.2+ with CDI:

import javax.inject.Named;
import javax.faces.view.ViewScoped;

@Named
@ViewScoped

See also:

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