gpt4 book ai didi

xpages - 如何以编程方式构建控件?

转载 作者:行者123 更新时间:2023-12-04 19:14:48 24 4
gpt4 key购买 nike

我有用 Java 编写的自定义控件。为了简单起见,我们假设它看起来像这样:

public class HelloworldControl extends UIComponentBase {
@Override
public void decode(FacesContext context) {
String cid = this.getClientId(context);
...
super.decode(context);
}

@Override
public void encodeBegin(FacesContext context) throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.writeText("Hello world!", this);
// I want a view!!
}

@Override
public void encodeEnd(FacesContext context) throws IOException {
ResponseWriter writer = context.getResponseWriter();
...
}

public void restoreState(FacesContext context, Object state) {
Object values[] = (Object[]) state;
...
super.restoreState(context, values[0]);
}

public Object saveState(FacesContext context) {
Object values[] = ...
}
}

我想以编程方式添加子控件。例如,我想要一个 subview 控件在 Hellow 世界文本下呈现一个 View 。

我怎样才能做到这一点?动态构建控件的标准程序是什么?

简而言之 - 我想以编程方式构建标准组件的层次结构,并且我想将它附加到我的控件上。

最佳答案

我认为您正在寻找的答案是实现 FacesComponent 接口(interface) Keith Strickland 在他的博客上发布了详细说明:

http://xprentice.gbs.com/A55BAC/keithstric.nsf/default.xsp?documentId=82770C11FA7B9B21852579C100581766

它使用 initBeforeContents、buildContents 和 initAfterContents 方法允许您添加子项。

希望有帮助。

关于xpages - 如何以编程方式构建控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10948275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com