在 JSF2 中制作复合组件
我的 JSF2 中的复合组件有问题。我使用 ui 和 li 实现一个列表。但如果我使用我的组件,什么也不会发生。我的列表标签不会在 Facelet 生成的代码中被替换。那么这有什么问题呢。
复合组件存储在/resources/util/list.xhtml 下。这是代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets">
<head><title>(For validation only)</title></head>
<body>
<composite:interface>
<composite:attribute name="values"/>
<composite:attribute name="listStyle"/>
<composite:attribute name="elementStyle"/>
</composite:interface>
<composite:implementation>
<ul class="#{cc.attrs.listStyle}">
<ui:repeat var="element" value="#{cc.attrs.values}">
<li class="#{cc.attrs.elementStyle}">#{element}</li>
</ui:repeat>
</ul>
</composite:implementation>
</body></html>
我以这种方式使用我的标签
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:core="http://java.sun.com/jsf/core"
xmlns:utils="http://http://java.sun.com/jsf/composite/utils">
<h:head>
<title>Show user Color</title>
<style type="text/css">
.elements { font-style: italic; }
.list { margin: 0px; padding:0px;}
</style>
</h:head>
<h:body>
<h1>Show Color</h1>
<p>User selected: #{ColorBean.selectedColor}</p>
<p>User set hex: #{ColorBean.showHex == true? "yes": "no"}</p>
<p><h:outputFormat value="#{msgs.hexNotification}"
rendered="#{ColorBean.showHex}">
<core:param value='#{ColorBean.showHex == true? "yes": "no"}' />
</h:outputFormat>
</p>
<fieldset><legend>Colors</legend>
<utils:list values="#{ColorBean.colors}" listStyle="list" elementStyle="elements"/>
</fieldset>
</h:body>
</html>
这是生成的代码。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:utils="http://http://java.sun.com/jsf/composite/utils"><head>
<title>Show user Color</title>
<style type="text/css">
.elements { font-style: italic; }
.list { margin: 0px; padding:0px;}
</style></head><body>
<h1>Show Color</h1>
<p>User selected: green</p>
<p>User set hex: no</p>
<p>
</p>
<fieldset><legend>Colors</legend>
<utils:list values="[Ljava.lang.String;@13e86ec" listStyle="list" elementStyle="elements"></utils:list>
</fieldset><div id="javax_faces_developmentstage_messages"></div></body>
</html>
这里出了什么问题。我使用教程来构建此代码。
http://courses.coreservlets.com/Course-Materials /pdf/jsf/jsf2/JSF2-Looping.pdf
他们在最后几页做了类似的例子。
我希望你能帮助我
谢谢
I have a problem with my composite component in JSF2. I implement a list using ui and li. But if I use my component nothing happens. My list-tag is not replaced in code generated by facelet. So whats wrong with this.
The composite component is stored under /resources/util/list.xhtml. Here is the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets">
<head><title>(For validation only)</title></head>
<body>
<composite:interface>
<composite:attribute name="values"/>
<composite:attribute name="listStyle"/>
<composite:attribute name="elementStyle"/>
</composite:interface>
<composite:implementation>
<ul class="#{cc.attrs.listStyle}">
<ui:repeat var="element" value="#{cc.attrs.values}">
<li class="#{cc.attrs.elementStyle}">#{element}</li>
</ui:repeat>
</ul>
</composite:implementation>
</body></html>
I use my tag this way
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:core="http://java.sun.com/jsf/core"
xmlns:utils="http://http://java.sun.com/jsf/composite/utils">
<h:head>
<title>Show user Color</title>
<style type="text/css">
.elements { font-style: italic; }
.list { margin: 0px; padding:0px;}
</style>
</h:head>
<h:body>
<h1>Show Color</h1>
<p>User selected: #{ColorBean.selectedColor}</p>
<p>User set hex: #{ColorBean.showHex == true? "yes": "no"}</p>
<p><h:outputFormat value="#{msgs.hexNotification}"
rendered="#{ColorBean.showHex}">
<core:param value='#{ColorBean.showHex == true? "yes": "no"}' />
</h:outputFormat>
</p>
<fieldset><legend>Colors</legend>
<utils:list values="#{ColorBean.colors}" listStyle="list" elementStyle="elements"/>
</fieldset>
</h:body>
</html>
Here is the generated code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:utils="http://http://java.sun.com/jsf/composite/utils"><head>
<title>Show user Color</title>
<style type="text/css">
.elements { font-style: italic; }
.list { margin: 0px; padding:0px;}
</style></head><body>
<h1>Show Color</h1>
<p>User selected: green</p>
<p>User set hex: no</p>
<p>
</p>
<fieldset><legend>Colors</legend>
<utils:list values="[Ljava.lang.String;@13e86ec" listStyle="list" elementStyle="elements"></utils:list>
</fieldset><div id="javax_faces_developmentstage_messages"></div></body>
</html>
What is wrong here. I use an tutorial to build this code.
http://courses.coreservlets.com/Course-Materials/pdf/jsf/jsf2/JSF2-Looping.pdf
They did a similar example on the last pages.
I hope you can help me
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改您的
xmlns:utils="http://http://java.sun.com/jsf/composite/utils">
到
xmlns:utils="http://java.sun.com/jsf/composite/utils">
法规,
抢
Change your
xmlns:utils="http://http://java.sun.com/jsf/composite/utils">
to
xmlns:utils="http://java.sun.com/jsf/composite/utils">
Regs,
Rob