1

我已从 PrimeFaces 3.5 切换到 4.0。

我收到“tieredMenu”的错误:

java.lang.IllegalArgumentException: component identifier's first character must be a letter or an underscore ('_')! But it is "0"

我已将此跟踪到“BaseMenuModel.class”,方法是“generateUniqueIds”:

public void generateUniqueIds() 
{
    this.generateUniqueIds(getElements(), null);
}
 private void generateUniqueIds(List<MenuElement> elements, String seed) {
        if(elements == null || elements.isEmpty()) {
            return;
        }

        int counter = 0;

        for(MenuElement element : elements) {
            String id = (seed == null) ? String.valueOf(counter++) : seed + "_" + counter++;
            element.setId(id);

            if(element instanceof MenuGroup) {                
                generateUniqueIds(((MenuGroup) element).getElements(), id);
            }
        }
    }

似乎它会生成以数字开头的 ID,因为seedis null

这是预期的吗?

编辑1: 豆代码:

public String initActionMenus() throws Exception
{
    ExpressionFactory factory =   FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
    MethodExpression methodsExpressionDelete = factory.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{UserGroupMgmtBean.menuDeleteAction}", null, new Class[]{ActionEvent.class});
    MethodExpressionActionListener actionListenerDelete = new MethodExpressionActionListener(methodsExpressionDelete);

    model = new DynamicMenuModel();
    UISubmenu smAction = new UISubmenu();       
    smAction.setLabel("Action");

    UIMenuItem itemDelete = new UIMenuItem();
    itemDelete.setValue("Delete");
    itemDelete.setUpdate(UPDATE_AREA_ID);
    itemDelete.setAjax(true);
    itemDelete.addActionListener(actionListenerDelete);
    smAction.getChildren().add(itemDelete);

    model.addElement(smAction);
    return "OK";
}

xml代码:

<p:tieredMenu model="#{UserGroupMgmtBean.model}" id="userGroupMenu"/>
4

0 回答 0