0

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?

hiaslosch17
  • 67
  • 3
  • 14
  • post your managed bean code first. – Makky Feb 27 '14 at 18:28
  • I need to show a list of roles who are dynamicly generated, so i can not use `` because i don't know how many roles are shown. – hiaslosch17 Feb 27 '14 at 19:28
  • Try removing immediate=true – Ali Cheaito Feb 27 '14 at 20:35
  • Where is the `` in this picture? The most probable culprit here is a conversion/validation error and seeing as you're submitting the entire form using `submit()` (which is entirely unnecessary, you should be using ajax instead), any component on the page may be blocking the form submission – kolossus Feb 27 '14 at 20:43
  • @phoenix yes, it works without the immediate="true". Thanks a lot! @kolossus that is only a part of my page. Actually there is another datatable in the page. And around the datatable and the overlayPanel there is the ``. – hiaslosch17 Feb 27 '14 at 21:19
  • @kolossus what would be the command if i don't want to update the whole form and use ajax instead? – hiaslosch17 Feb 27 '14 at 21:19
  • @hiaslosch17 nothing. Just add a `` – kolossus Feb 27 '14 at 21:37
  • You're welcome. I'll post it as the answer then :) – Ali Cheaito Feb 28 '14 at 00:07

1 Answers1

0

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

Community
  • 1
  • 1
Ali Cheaito
  • 3,746
  • 3
  • 25
  • 30