2010-03-23 27 views
1

我開始使用netbeans來設計表單來編輯我在我寫的一個小應用程序中創建的各種類的實例。基本上,應用程序啓動時,從數據庫中選擇一組初始對象並顯示在列表中,然後可以選擇列表中的項目進行編輯。當編輯器出現時,它爲表格中的許多數據字段提供了表單字段。如何使JPA POJO課程+ Netbeans表單在一起玩得很好?

我遇到的問題是我必須創建一個控制器,將每個數據元素映射到正確的表單元素,並創建一個數量過小的轉換映射代碼行,以將數字轉換爲字符串並設置在下拉菜單中輸入正確的元素,然後選擇另一個過多的代碼返回,並在單擊保存按鈕時使用表單中的所有值更新底層對象。

我的問題是;有沒有一種更直接的方式來直接修改我的類實例的內容來編輯表單?我希望能夠擁有一個我可以配置的默認映射「控制器」,然後根據需要覆蓋特定字段的getter/setter。理想情況下,將有標準的字段驗證,如電話號碼,整數,浮動,郵政編碼等...

我不反對自己寫這個,我只想看看它是否已經出來那裏並使用正確的工具來完成正確的工作。

回答

1

看到我對你的其他問題的答案here。 (簡而言之:使用bean綁定有點幫助,我希望)

2

有許多方法,

JBoss Seam,例如,使用Ant(不論你不知道,NetBeans使用Ant的幕後)稱爲hbmtemplate工具。它是一個基於模板的引擎,可以由用戶提供的模板或類來控制。隨着Freemarker模板(.flt擴展名),它會生成所有的應用程序。如果您想了解Seam如何生成其應用程序,請查看<SEAM_HOME>/seam-gen/view。在那裏,你可以看到許多Freemarker模板。

這裏是煤層如何產生及其應用

<hibernate templatepath="${templates.dir}"> 
    <jpaconfiguration persistenceunit="${project.name}"/> 
    <classpath> 
     <dirset dir="${project.home}/exploded-archives"> 
      <include name="*.war/WEB-INF/classes" if="project.war"/> 
      <include name="*.war/WEB-INF/dev" if="project.war"/> 
      <include name="*.jar" if="project.ear"/> 
     </dirset> 
    </classpath> 
    <property key="hibernatetool.util.toolclass" value="org.jboss.seam.tool.Util"/> 
     <hbmtemplate filepattern="{class-name}List.xhtml" template="view/list.xhtml.ftl" destdir="${project.home}/view" foreach="entity"/> 
     <hbmtemplate filepattern="{class-name}.xhtml" template="view/view.xhtml.ftl" destdir="${project.home}/view" foreach="entity"/> 
     <hbmtemplate filepattern="{class-name}.page.xml" template="view/view.page.xml.ftl" destdir="${project.home}/view" foreach="entity"/> 
     <hbmtemplate filepattern="{class-name}Edit.xhtml" template="view/edit.xhtml.ftl" destdir="${project.home}/view" foreach="entity"/> 
     <hbmtemplate filepattern="{class-name}Edit.page.xml"    template="view/edit.page.xml.ftl" destdir="${project.home}/view" foreach="entity"/> 
     <hbmtemplate filepattern="${action.dir}/{class-name}List.java" template="src/EntityList.java.ftl" destdir="${project.home}/src" foreach="entity"> 
      <property key="actionPackage" value="${action.package}"/> 
     </hbmtemplate> 
     <hbmtemplate filepattern="{class-name}List.page.xml" template="view/list.page.xml.ftl" destdir="${project.home}/view" foreach="entity"/> 
     <hbmtemplate filepattern="${action.dir}/{class-name}Home.java" template="src/EntityHome.java.ftl" destdir="${project.home}/src" foreach="entity"> 
      <property key="actionPackage" value="${action.package}"/> 
     </hbmtemplate> 
     <hbmtemplate filepattern="menu.xhtml" template="view/layout/menu.xhtml.ftl" destdir="${project.home}/view/layout" foreach="entity"/> 
    </hibernate> 

這裏去一些代碼,不是所有的,從自由市場模板view.xhtml.ftl

<#foreach property in pojo.allPropertiesIterator> 
    <#if !c2h.isCollection(property) && !isToOne(property) && property != pojo.versionProperty!> 
     <#include "viewproperty.xhtml.ftl"> 
    </#if> 
</#foreach> 

我希望它可以是有用的你

相關問題