我写了一个自定义标签扩展UIComponentBase.
它在encodeBegin方法期间添加了多个子组件(UIComponent).
出于布局目的,我想将此子组件嵌套在h:panelGrid中,
但是标签在这里很麻烦.
ExampleTag.java
private ExampleTag extends UIComponentBase {
public void encodeBegin(FacesContext context) throws IOException {
getChildren().add(new HtmlLabel());
getChildren().add(new HtmlOutputText();
}
}
ExampleOutput.xhtml
生成的输出将在同一单元格中具有HtmlLabel和HtmlOutput组件,
但我想将它们排成一排,即两个单元格.
解决方法:
> h:panelGrid仅控制其自己子级的布局(而不是其子级的子级)
>每个< foo:exampleTag />创建一个复合控件(带有自己的子控件)
如果要将多个控件添加到h:panelGrid,请使用其他模板机制之一.
例如,此h:panelGrid使用ui:include:
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
视图输出的子集:
Hello, | World! |
Hello, | Nurse! |
请注意上述实现-您不能在gridme.xhtml中的任何内容上显式设置ID,因为没有复合控件,因此也没有NamespaceContainer来确保子项具有唯一的名称空间.
组件不是标签.
public void encodeBegin(FacesContext context) throws IOException {
getChildren().add(new HtmlLabel());
getChildren().add(new HtmlOutputText();
}
这不是建立复合控件的可接受方法.如果执行此操作,则每次渲染时都会将新控件添加到组件中.您也不应在构造函数中执行此操作;那也会导致问题.没有好的方法可以在控件中添加子控件.应该通过视图(参见上文)或a tag从外部完成.
标签:uicomponents,jsf,facelets,java,tags
来源: https://codeday.me/bug/20191208/2091413.html