JSF ResponseWriter 自定义组件
我了解 ResponseWriter 上的 startElement、endElement 和 writeAttribute 方法。 我的问题是,我想通过像 HtmlCommandLink link = new HtmlCommandLink();
那样声明来输出 ah:commandLink 。
如何在我自己的组件中输出这样的其他 UIComponent? 我可能还想在我的组件中使用一些 RichFaces ajax 的东西,所以希望我可以避免从头开始做这一切。
编辑:我想要做的是使用以下标签
创建我自己的标签库。 每个评论都有一个回复按钮,当单击回复按钮时,我会在评论下方呈现回复表单。 一旦渲染完成,我想输出例如 richfaces
组件。 这必须在我自己的 java 标记文件中完成,我调用了 CommentsTreeUI.java
。
通常,我使用 writer.startElement("input", myComponent); 输出显示表单和按钮的所有元素; writer.writeAttribute("type", "button", null); 但如果我可以这样做,例如 startElement("a4j:commandbutton", myComponent)
这将对我有很大帮助,因为它具有所有内置的 ajax 功能等。
有任何线索吗?
I know about startElement, endElement, and writeAttribute methods on ResponseWriter. My problem is that I want to for example output a h:commandLink by declaring it like HtmlCommandLink link = new HtmlCommandLink();
.
How can I output other UIComponents like this in my own component? I might want to use some RichFaces ajax stuff in my components aswell so hoping I can avoid making it all by scratch.
Edit: What I'm trying to do is create my own tag library with the following tag <myTags:commentTree>
. Every comment have a reply button, when the reply button is clicked I render the reply form beneath the comment. Once that is rendered, I would like to output for example the richfaces <a4j:commandButton>
component. This have to be done inside my own java tag file which Ive called for CommentsTreeUI.java
.
Normally I output all my elements that display the forms and buttons with writer.startElement("input", myComponent); writer.writeAttribute("type", "button", null);
but if I could instead do for example startElement("a4j:commandbutton", myComponent)
that would help my ALOT since it has all the built in ajax features etc.
Any clues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过使用添加新组件解决了这个问题
This problem was solved by adding new components by using
您可以这样做:
它确实取决于您想要对子组件执行的操作,即如果您希望它们被自定义 HTML 包围(例如,在 HTML 列表中),您将需要更复杂的东西。
You can do something like this:
It does depend on what you want to do with the child components though i.e. if you want them surrounded with custom HTML (in an HTML list, for example) you will need something a bit more complex.
制作复合控件的一种方法是使用 binding 属性将标记与您自己的代码关联:
faces-config.xml 中的 bean 配置:
bean 代码:
One approach to making composite controls is to use the binding attribute to associate the tag with your own code:
The bean configuration in faces-config.xml:
The bean code: