Primefaces:选择Check Box菜单:NullPointerException

时间:2013-10-26 14:56:51

标签: java jsf jsf-2 primefaces

我的项目中有selectCheckBoxMenu的实现。我的xhtml文件中的部分代码是: -

<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>

我的Bean类有代码: -

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);
    }
}

当我从下拉列表中选择任何值并提交时。我得到例外 -

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)

我在网上找不到太多帮助。请提出我缺少的内容。

1 个答案:

答案 0 :(得分:2)

仔细查看错误,我一直在浏览Primefaces的SelectCheckboxMenu类并找到这段代码(Primefaces 3.5 SelectCheckboxMenu:199):

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

由于某种原因,您的eventName会解析为null,并获得NPE。它似乎与此Primefaces bug有关。

无论如何,您提供的代码就像4.0版本中的魅力一样,所以如果可以,您应该考虑升级。