我已从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,因为seed
是null
。
这是预期的吗?
编辑1: Bean代码:
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";
}
xthml代码:
<p:tieredMenu model="#{UserGroupMgmtBean.model}" id="userGroupMenu"/>