我正在overlayPanel中编写SelectOneMenu。问题是所选值在bean中始终为null。没有调用setter方法,所以我认为当我选择一个项目时不会提交SelectOneMenu。
这是我的页面:
<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;
}
有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
总结评论,删除immediate =“true”纠正了这种情况下的问题。但是,使用onchange =“submit()”应替换为&lt; f:ajax&gt;如果使用jsf 2.0+。请参阅此处的相关文章:
h:selectOneMenu onchange="submit()" immediate="true" does not skip validation of other inputs