我正在尝试根据 Keith Strickland 的示例为 XPages 构建 JSF 库控件。
我在构建 FileDownloadControl 时遇到了一些麻烦这是我构建的代码:
public class Libcontrol extends UIComponentBase implements FacesComponent {
private static final String RENDERER_TYPE = "de.chris.Libcontrol ";
private static final String COMPONENT_FAMILY = "de.chris";
public Libcontrol() {
setRendererType(RENDERER_TYPE);
}
@Override
public String getFamily() {
return COMPONENT_FAMILY;
}
@SuppressWarnings("unchecked")
public void initBeforeContents(FacesContext arg0) throws FacesException {
FacesContext context;
ExpressionEvaluatorImpl evaluator;
context = FacesContext.getCurrentInstance();
evaluator = new ExpressionEvaluatorImpl(context);
XspFileDownload result = new XspFileDownload();
String sourceId = "fileDownload1/@value";
String valueExpr = "#{document1.FileField}";
ValueBinding value = evaluator.createValueBinding(result, valueExpr, sourceId,Object.class);
result.setValueBinding("value", value);
result.setDisplayLastModified(true);
result.setAllowDelete(true);
result.setTitle("filedown");
result.setRows(30);
result.setId("fileDownload1");
this.getChildren().add(result);
}
public void buildContents(FacesContext arg0, FacesComponentBuilder arg1) throws FacesException {
// Do Nothing
}
public void initAfterContents(FacesContext arg0) throws FacesException {
// Do nothing
}
}
为什么控件没有完全渲染?当我查看 HTML 代码时,我看到来自控件的 starttag,但没有要下载的文件,是的,我已将文件上传到相应的 NotesDocument。
这是我分别复制的渲染器:
public class MainLibcontrolRenderer extends Renderer {
@Override
public void encodeBegin(FacesContext context, UIComponent component) {
try {
super.encodeBegin(context, component);
context = FacesContext.getCurrentInstance();
UIViewRootEx rootEx = (UIViewRootEx) context.getViewRoot();
/*rootEx.setDojoParseOnLoad(true);
rootEx.setDojoTheme(true);*/
ResponseWriter writer = context.getResponseWriter();
writer.startElement("fieldset", component);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void encodeChildren(FacesContext context, UIComponent component) {
try {
super.encodeChildren(context, component);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void encodeEnd(FacesContext context, UIComponent component) {
try {
super.encodeEnd(context, component);
ResponseWriter writer = context.getResponseWriter();
writer.endElement("fieldset");
} catch (Exception e) {
e.printStackTrace();
}
}
}