如何将现有的 JSF 组件添加到我自己的自定义组件中?
我有一个扩展 UIComponent 和 UIOutput 的标签类。 在这个类中,我有encodeBegin和encodeEnd,我可以使用我的contextWriter通过使用writer.startElement(“div”,myComponent)等来输出我想要的任何html标签。
我现在的问题是我需要插入例如 a 而不是使用 writer.startElement 。 我可以通过执行 getChildren().add(HtmlCommandButton button = new HtmlCommandButton()); 来完成此操作 但是当这样做时,我似乎无法输出我希望它们出现的组件,就像我可以使用 write.startElement 一样。
有没有人有任何好的解决方案来帮助我如何在我自己的标签库中利用 richfaces 标签、JSF 标签和类似标签? 简而言之,我真正想做的是在我的encodeBegin内部:
writer.startElement("a4j:commandButton", myComponent);
writer.writeAttribite("action", "#{Handler.myAction}", null);
writer.endElement("a4j:commandButton");
提前致谢
I have a tag class which extends UIComponent and UIOutput. In this class I have encodeBegin and encodeEnd which I can use my contextWriter to output any kinda html tag I want too by using writer.startElement("div", myComponent) and so on.
My problem now is that I need to insert for example a instead of using the writer.startElement. I can get this done by doing getChildren().add(HtmlCommandButton button = new HtmlCommandButton()); but when doing it like that I cant seem to output the component where I want them to appear, like I can with write.startElement.
Does anyone have any good solutions in how I can take advantage of richfaces tags, JSF tags and similar in my own taglibrary? In short what I would really want to do is inside my encodeBegin:
writer.startElement("a4j:commandButton", myComponent);
writer.writeAttribite("action", "#{Handler.myAction}", null);
writer.endElement("a4j:commandButton");
Thanks by advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能按照您的意愿使用ResponseWriter。 我可以想到如何以编程方式添加子控件的两种方法是通过绑定属性(查看此答案)或通常创建控件的位置(在 JSP 中,位于 标签类)。
JSF 组件可以通过两种方式包含其他控件:作为子控件或作为命名方面。 组件始终控制它们渲染面的方式; 如果要渲染其子级,则必须为 getRendersChildren。
这是未经测试的代码,但顺序如下:
You cannot use the ResponseWriter as you wish to. Two ways I can think of how to add child controls programmatically are either via the binding attribute (see this answer) or in the place where controls usually get created (in JSPs, that is in the tag class).
There are two ways for JSF components to contain other controls: as children or as named facets. Components always control how they render their facets; if they are to render their children, they must return true for getRendersChildren.
This is untested code, but the sequence goes something like this:
并不是真正的答案,更多的是猜测,但也许您可以扩展其中一个facelets控件?
或者,要么直接使用facelets——这似乎正是你想要的,尽管我自己没有使用过它。 或者,您可以在想要显示 HTML 的位置添加 UIOutput 控件,并将每个控件的值设置为您想要显示的 HTML - 这正是 f:verbatim 在幕后所做的事情,或者从源代码来看似乎是这样:- )
Not really an answer, more of a guess, but maybe you could extend one of the facelets controls?
Alternatively, either use facelets directly - which seems to be exactly what you want really though I've not used it myself. Or you could add UIOutput controls where you want HTML to appear and set the value of each to the HTML you want to appear - this is exactly what f:verbatim does under the hood, or so it seems from looking at the source code :-)