【发布时间】:2016-07-17 06:40:45
【问题描述】:
查看以下简化代码:
test.xhtml
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:o="http://omnifaces.org/ui"
xmlns:test="http://xmlns.jcp.org/jsf/composite/test">
<body>
<h:form>
<h1>Nested - not working</h1>
<test:parentComp />
<h1>Not nested - working</h1>
<o:tree value="#{testModel.treeModel}">
<o:treeNode>
<ul>
<o:treeNodeItem>
<test:childComp />
<o:treeInsertChildren />
</o:treeNodeItem>
</ul>
</o:treeNode>
</o:tree>
</h:form>
</body>
</html>
parentComp.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:o="http://omnifaces.org/ui"
xmlns:cc="http://xmlns.jcp.org/jsf/composite"
xmlns:test="http://xmlns.jcp.org/jsf/composite/test">
<cc:interface componentType="parentComp">
</cc:interface>
<cc:implementation>
<div id="#{cc.clientId}">
<o:tree value="#{cc.treeModel}">
<o:treeNode>
<ul>
<o:treeNodeItem>
<test:childComp />
<o:treeInsertChildren />
</o:treeNodeItem>
</ul>
</o:treeNode>
</o:tree>
</div>
</cc:implementation>
</html>
childComp.xhtml
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:cc="http://xmlns.jcp.org/jsf/composite"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<cc:interface componentType="childComp">
</cc:interface>
<cc:implementation>
<div id="#{cc.clientId}">
<h:commandLink action="#{cc.childAction}" value="Click" />
</div>
</cc:implementation>
</html>
父组件.java
@FacesComponent("parentComp")
public class ParentComponent extends UINamingContainer {
private TreeModel treeModel;
public ParentComponent() {
this.treeModel = new ListTreeModel();
this.treeModel.addChild("1").addChild("1.1");
this.treeModel.addChild("2").addChild("2.2");
}
public TreeModel getTreeModel() {
return treeModel;
}
}
ChildComponent.java
@FacesComponent("childComp")
public class ChildComponent extends UINamingContainer {
public void childAction() {
}
}
TestModel.java
@RequestScoped
@Named
public class TestModel {
private TreeModel treeModel;
public TestModel() {
this.treeModel = new ListTreeModel();
this.treeModel.addChild("1").addChild("1.1");
this.treeModel.addChild("2").addChild("2.2");
}
public TreeModel getTreeModel() {
return treeModel;
}
}
在示例中,在复合组件中使用了 o:tree,子组件的#{cc} 被错误解析,如果你点击链接你会得到这样的异常:
Caused by: javax.el.MethodNotFoundException: /resources/test/childComp.xhtml @10,71 action="#{cc.childAction}": Method not found: ParentComponent@422dcfd4.childAction()
如果 o:tree 没有像第二个示例那样嵌套在复合组件中,则命令链接按预期工作。
这是 Omnifaces 中的错误吗?我在这里做错了吗?
【问题讨论】:
标签: jsf jsf-2.2 composite-component omnifaces