JSF 1.2 Facelets 自定义组件
我正在尝试在 JSF 1.2 中开发自定义控件(使用facelets)。
我按照不同教程中的步骤(定义 .tld、taglib.xml、faces-config.xml 中注册的组件并实现 UIComponent(组件呈现自身)和 UIComponentELTag 类),并且我的组件已呈现,我有绑定到它的值,但是属性我为该标签定义的内容将被忽略。我在 Tag 类中记录了各种方法,并注意到没有一个方法被调用。
我缺少什么?标签处理程序类从未被调用是否有原因?
提前致谢。
我的 taglib.xml 文件是:
<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>dynamissoft.com/entities/ui</namespace>
<tag>
<tag-name>legalEntityView</tag-name>
<component>
<component-type>rs.bozic.wastemanager.LegalEntityView</component-type>
</component>
</tag>
</facelet-taglib>
I am trying to develop custom control in JSF 1.2 (using facelets).
I followed steps from different tutorials (defining .tld, taglib.xml, registered component in faces-config.xml and implementing UIComponent (component renders itself) and UIComponentELTag classes) and my component is rendered, I have value bound to it, but attributes I defined for that tag are ignored. I logged various methods in Tag class and noticed that none of the methods is ever called.
What am I missing? Is there a reason Tag handler class is never invoked?
Thanks in advance.
My taglib.xml file is:
<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>dynamissoft.com/entities/ui</namespace>
<tag>
<tag-name>legalEntityView</tag-name>
<component>
<component-type>rs.bozic.wastemanager.LegalEntityView</component-type>
</component>
</tag>
</facelet-taglib>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过使用facelets(仅限xml)创建自定义组件。这是最简单的方法,使用facelets,通常不再需要不同的java类。
非常粗略的概述:
您可以将值/bean传递给您的使用普通标签参数的组件:
使用组件
组件
Param1 内部刚刚打印:#{myParam2}
Param2 用作表的值
...
Google 上有很棒的教程,例如来自IBM。
如果可能,请考虑使用 JSF 2.0。 Facelet 是集成的,您可以更灵活地创建自定义组件。我不久前创建了一篇博客文章: http:// blog.whitehorses.nl/2010/02/08/jsf-2-0/ (或 Google 自己)
Have you tried creating a custom component using facelets (xml only). That's the most easy way, using facelets, usually, the different java classes aren't needed anymore.
Very rough overview:
You can pass values/beans to your component using normal tag paramets:
Using the component
Inside the component
Param1 is just printed: #{myParam2}
Param2 used as value for table
...
There are excellent tutorials on Google, like the one from IBM.
If possible, consider using JSF 2.0. Facelets are integrated, and you have more flexibility to create your custom components. I created a blog posting a while ago on that: http://blog.whitehorses.nl/2010/02/08/jsf-2-0/ (or Google yourself)
只是为了扩展 Gerbrand 的答案,这里有一个简单的 Facelets 兼容组件的过程。它呈现一个
span
标签,该标签包装通过组件的text
属性指定的文本。首先创建组件类(在我们的例子中,它只是
UIOutput
):接下来,我们需要一个 taglib XML 文件,我们将其命名为
mytag.taglib.xml
并将其放入WEB-INF
中> 目录。请注意:
.taglib.xml
后缀为必填
应该具有相同的组件的
getFamily()
方法返回的值将 WEB-INF/facelet-taglib_1_0.dtd 替换为
http://java.sun.com/dtd/facelet-taglib_1_0.dtd
是时候修改 web.xml 和 faces-config.xml 了。
前者应修改为
faces-config.xml 应该得到
<前><代码><组件>
<组件类型>myTag.组件
<组件类>sample.mytag.LabelComponent
We're good to go!
Just to expand Gerbrand's answer a bit, here's a procedure for a simple Facelets-compatible component. It renders a
span
tag that wraps a text specified via component'stext
attribute.First create the component class (in our case it's just a flavour of
UIOutput
):Next, we need a taglib XML file, let's call it
mytag.taglib.xml
and put it insideWEB-INF
dir.Note that:
.taglib.xml
suffix is mandatory<component-type>
should have the samevalue that is returned by component's
getFamily()
methodreplace
WEB-INF/facelet-taglib_1_0.dtd
withhttp://java.sun.com/dtd/facelet-taglib_1_0.dtd
It's time to modify web.xml and faces-config.xml.
Former should be modified with
faces-config.xml should get
We're good to go!