theGamblerRises
theGamblerRises

Reputation: 696

Primefaces : Select Check Box menu : NullPointerException

I have an implementation of selectCheckBoxMenu in my project. Part of code from my xhtml file is :-

<p:row >
    <p:column style=" width: 497px; text-align: right;">
        <h:outputText for="toMails" value="To : " />  
    </p:column>
    <p:column style=" width: 497px; text-align: left;">
        <p:selectCheckboxMenu id="toMails" value="#{schedule.selectedEmailIds}" label="Mail Recipients" filter="true" 
            filterText="Filter" filterMatchMode="startsWith" panelStyle="width:220px">  
            <f:selectItems value="#{schedule.users}" />  
        </p:selectCheckboxMenu>
    </p:column>
</p:row>

My Bean Class has the code:-

private String[] selectedEmailIds;  

private Map<String,String> users; 

//Getters and Setters

//Value Loader Method
public void loadWorkFlowServices()
{
    try
    {           
        Map<String, String> tmpUsers = new HashMap<String, String>();  
        tmpUsers.put("Scarface", "Scarface");  
        tmpUsers.put("Goodfellas", "Goodfellas");  
        tmpUsers.put("Godfather", "Godfather");  
        tmpUsers.put("Carlito's Way", "Carlito's Way"); 
        tmpUsers.put("Rang De Basanti", "Rang De Basanti"); 
        tmpUsers.put("Despicable Me", "Despicable Me"); 
        tmpUsers.put("The Dark Knight", "The Dark Knight"); 
        setUsers(tmpUsers);
    }
    catch (Exception e)
    {
        LOGGER.error("Error while loading the workflow services.", e);
    }
}

When I select any value from drop down and submit it. I am getting exception -

Error occurred while doing security check on URL hit
java.lang.NullPointerException
at org.primefaces.component.selectcheckboxmenu.SelectCheckboxMenu.queueEvent(SelectCheckboxMenu.java:199)
at javax.faces.component.UIInput.validate(UIInput.java:976)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1233)
at javax.faces.component.UIInput.processValidators(UIInput.java:698)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIForm.processValidators(UIForm.java:253)

I can't find much help online. Please suggest what I am missing.

Upvotes: 1

Views: 1795

Answers (1)

Aritz
Aritz

Reputation: 31679

Looking through your error, I've been browsing Primefaces' SelectCheckboxMenu class and found this piece of code (Primefaces 3.5 SelectCheckboxMenu:199):

if(event instanceof AjaxBehaviorEvent && eventName.equals("toggleSelect"))

Here your eventName resolves to null for some reason and you get a NPE. It seems to be related with this Primefaces bug.

Anyway, your provided code works like a charm in 4.0 version, so you should consider an upgrade if you can.

Upvotes: 2

Related Questions