Primefaces SelectOneMenu: Selected item is not set in Managed Bean
-
23-12-2019 - |
Question
I am programming a SelectOneMenu in an overlayPanel. The problem is that the selected value is always null in the bean. The setter method is not called, so i think that the SelectOneMenu is not submitted when i select an item.
Here is my page:
<p:overlayPanel id="OverLayPanelNewRole" for="buttonAddRole">
<p:selectOneMenu id="SelectOneMenuRoles" value="#{userSettingBean.selectedRole}"
onchange="submit()" immediate="true">
<f:selectItems value="#{userSettingBean.roleList}" var="role" itemLabel="#{role.NAME}" style="width:100%"/>
</p:selectOneMenu>
</p:overlayPanel>
My Managed Bean:
@ManagedBean(name = "userSettingBean")
@SessionScoped
public class UserSettingBean implements Serializable {
private static final long serialVersionUID = -7579402702068562565L;
@ManagedProperty(value= "#{roleServiceImpl}")
private RoleService roleService;
private List<Role> roleList;
private Role selectedRole;
@PostConstruct
public void init(){
//init Roles for selection in overlayPanel
roleList=roleService.findAllRole();
}
public RoleService getRoleService() {
return roleService;
}
public void setRoleService(RoleService roleService) {
this.roleService = roleService;
}
public List<Role> getRoleList() {
return roleList;
}
public void setRoleList(List<Role> roleList) {
this.roleList = roleList;
}
public Role getSelectedRole() {
return selectedRole;
}
public void setSelectedRole(Role selectedRole) {
this.selectedRole = selectedRole;
}
Can anybody help me with this problem?
Solution
To summarize the comments, removing immediate="true" corrected the issue in this case. However, using onchange="submit()" should be replaced with <f:ajax> if using jsf 2.0+. See the relevant post here:
h:selectOneMenu onchange="submit()" immediate="true" does not skip validation of other inputs
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow