DropWizard と Freemarker を使用して、Web サービスの結果に基づいてさまざまな種類のフォームを表示するビューを構築しています。
ビューとしてフォームを作成しました-それぞれに独自のftlがあります。
そのため、私のリソースでは、必要なフォームを見つけ、main.ftl を読み込み、フォーム ビューをパラメーターとして渡します (以下を参照)。
これはうまくいきません。私たちがどこで間違っているのか、誰にもわかりますか?または、DropWizard と freemarker を使用してビューを連鎖させるまったく別の方法はありますか?
@GET
public Form getForm() {
FormView view = new FormView(service.getForm());
return new MainView(view);
}
public class FormView extends View {
private final Form form;
public FormView(Form form) {
super("formView.ftl");
this.form = form;
}
public Form getForm() {
return form;
}
}
public class MainView extends View {
private final FormView formView;
public MainView(FormView formView) {
super("main.ftl");
this.formView = formView;
}
public FormView getFormView() {
return formView;
}
}
public class TextForm extends View implements Form {
private int maxLength;
private String text;
public TextForm(int maxLength, String text) {
super("textForm.ftl");
this.maxLength = maxLength;
this.text = text;
}
public int getMaxLength() {
return maxLength;
}
public String getText() {
return text;
}
}
main.ftl
<#-- @ftlvariable formView="" type="MainView" -->
<html>
<body>
<#include formView.templateName /> // This evaluates to formView.ftl, but it seems to create a new instance, and doesn't have the reference to textForm.ftl. How do we reference a dropwizard view here?
</body>
</html>
formView.ftl
<#-- @ftlvariable form type="FormView" -->
${form?html} // also tried #include form.templateName
textForm.ftl
<#-- @ftlvariable text type="TextForm" -->
<div>${text?html}</div>