如何从 JSF 1.2 中的 Facelet 标记文件访问父组件
我正在 JSF 1.2 中编写 Facelet 标记文件。我希望能够引用父容器。在 JSF 2.0 中,我可以将其设为复合组件并使用 #{cc.parent}
。但是是否有一种与 JSF 1.2 等效的方法可以做到这一点?
taglib.xml
<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://company.com/jsf</namespace>
<tag>
<tag-name>parentid</tag-name>
<source>../components/parentid.xhtml</source>
</tag>
</facelet-taglib>
parentid.xhtml
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:ui="http://java.sun.com/jsf/facelets">
<!-- The next line is the line that isn't working for me -->
<h:outputText binding="#{obj}" value="Parent id is: #{obj.parent.id}" />
</ui:composition>
testpage.xhtml
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:test="http://company.com/jsf"
xmlns:ui="http://java.sun.com/jsf/facelets">
...
<a:form id="form1">
<test:parentid />
</a:form>
<a:form id="form2">
<test:parentid />
</a:form>
...
</ui:composition>
我编辑了它以包含来自 BalusC 链接的信息,而且我已经快完成了。
在示例中,如果只有 form1,则效果很好。但是添加 form2,这是我得到的输出:
Parent id is: form2
Parent id is: form2
我想要的是:
Parent id is: form1
Parent id is: form2
所以组合中的绑定将被最后一个绑定覆盖。我尝试使用地图并绑定到它,但这不起作用。 我该如何解决这个问题?
I am writing a Facelet tag file in JSF 1.2. I want to be able to reference the parent container. In JSF 2.0 I could make this a composite component and use #{cc.parent}
. But is there a JSF 1.2-equivalent way of doing this?
taglib.xml
<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://company.com/jsf</namespace>
<tag>
<tag-name>parentid</tag-name>
<source>../components/parentid.xhtml</source>
</tag>
</facelet-taglib>
parentid.xhtml
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:ui="http://java.sun.com/jsf/facelets">
<!-- The next line is the line that isn't working for me -->
<h:outputText binding="#{obj}" value="Parent id is: #{obj.parent.id}" />
</ui:composition>
testpage.xhtml
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:test="http://company.com/jsf"
xmlns:ui="http://java.sun.com/jsf/facelets">
...
<a:form id="form1">
<test:parentid />
</a:form>
<a:form id="form2">
<test:parentid />
</a:form>
...
</ui:composition>
I edited this to include the information from BalusC's link, and I'm almost there.
In the example, it works perfectly if there is just form1. But adding form2, this is the output I get:
Parent id is: form2
Parent id is: form2
What I want is:
Parent id is: form1
Parent id is: form2
So the binding in the composition is getting overwritten with whatever the last binding is. I tried to use a map and bind to that, but that didn't work.
How could I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论