我正在使用netbeans freemarker从Entity类生成JSF页面。 在list.ftl文件中,我有
<#list entityDescriptors as entityDescriptor>
<#if entityDescriptor.id != "id" && entityDescriptor.id != "version">
<div class="ui-g-12 ui-md-6 ui-lg-4">
<p:outputLabel styleClass="template-labels"
value="${r"#{"}${bundle}.${entityDescriptor.id?replace(".","_")}${r"}"}" for="@next" />
<#if entityDescriptor.dateTimeFormat?? && entityDescriptor.dateTimeFormat != "">
<p:inputMask mask="9999/99/99" id="${entityName}_editForm_${entityDescriptor.id?replace(".","_")}" value="${r"#{"}${managedBean}.selected${entityName}.${entityDescriptor.name?replace("item.","")}${r"}"}"
converter="JalaliDateConverter" onfocus="serp.showDatePicker(this)" styleClass="PersianDate template-fields" title="${r"#{"}${bundle}.${entityDescriptor.id?replace(".","_")}${r"}"}"
disabled="${r"#{"}!${managedBean}.${entityName?uncap_first}Editable${r"}"}"/>
<#elseif entityDescriptor.returnType?matches(".*[Bb]+oolean")>
<p:selectBooleanCheckbox styleClass="template-fields" id="${entityName}_editForm_${entityDescriptor.id?replace(".","_")}"
value="${r"#{"}${managedBean}.selected${entityName}.${entityDescriptor.name?replace("item.","")}${r"}"}"
disabled="${r"#{"}!${managedBean}.${entityName?uncap_first}Editable${r"}"}"/>
<#elseif entityDescriptor.blob>
<p:inputTextarea styleClass="template-fields" id="${entityName}_editForm_textArea" rows="4" cols="30" id="${entityDescriptor.id?replace(".","_")}"
value="${r"#{"}${entityDescriptor.name}${r"}"}" title="${r"#{"}${bundle}.${entityDescriptor.id?replace(".","_")}${r"}"}"
disabled="${r"#{"}!${managedBean}.${entityName?uncap_first}Editable${r"}"}"/>
<#elseif entityDescriptor.relationshipOne>
<p:selectOneMenu styleClass="template-fields" id="${entityName}_editForm_${entityDescriptor.id?replace(".","_")}" value="${r"#{"}${managedBean}.selected${entityName}.${entityDescriptor.name?replace("item.","")}${r"}"}"
disabled="${r"#{"}!${managedBean}.${entityName?uncap_first}Editable${r"}"}">
<f:selectItem itemLabel="${r"#{"}${bundle}.SelectOneMessage${r"}"}"/>
<f:selectItems value="${r"#{"}${entityDescriptor.valuesGetter}${r"}"}" var="${entityDescriptor.id?replace(".","_")}Item" itemValue="${r"#{"}${entityDescriptor.id?replace(".","_")}Item${r"}"}" itemLabel="${r"#{"}${entityDescriptor.id?replace(".","_")}Item.name${r"}"}"/>
</p:selectOneMenu>
<#elseif entityDescriptor.relationshipMany>
<p:selectManyMenu styleClass="template-fields" id="${entityName}_editForm_${entityDescriptor.id?replace(".","_")}" value="${r"#{"}${entityDescriptor.name}${r"}"}"
disabled="${r"#{"}!${managedBean}.${entityName?uncap_first}Editable${r"}"}">
<f:selectItems value="${r"#{"}${entityDescriptor.valuesGetter}${r"}"}" var="${entityDescriptor.id?replace(".","_")}Item" itemValue="${r"#{"}${entityDescriptor.id?replace(".","_")}Item${r"}"}"/>
</p:selectManyMenu>
<#elseif entityDescriptor.id != "id" && entityDescriptor.id != "version">
</#list>
entityDescriptor
具有entityDescriptor.blob
或entityDescriptor.relationshipOne
之类的字段,在哪里可以找到这些可能的变量,例如blob,id,valuesGetter或RelationshipOne?
我已经检查了freemarker.jar源文件及其网站文档,但似乎它更可能与netbeans向导有关。
ps:我正在寻找一个ManyToMany条件,并在此之前询问它是模糊还是误导。
答案 0 :(得分:0)
这取决于数据模型的实现细节,但是通常,如果可以执行entityDescriptor.blob
,则entityDescriptor?keys
应该给出一个包含"blob"
的列表。要掌握的想法是,在FTL中,entityDescriptor.blob
和entityDescriptor["blob"]
完全相同,因此entityDescriptor
有点像Map
,带有String
键(即使(不一定是Map
,FTL对此的看法与此类似)。因此,您甚至可以将键值对列出为<#list entityDescriptor as k, v>
,就像您自然希望从类似Map
的对象中看到的那样。