如何制作 JPA POJO 类 + Netbeans 表单可以很好地协同工作吗?
我开始使用 netbeans 设计表单来编辑我正在编写的小型应用程序中制作的各种类的实例。基本上,应用程序启动时,从数据库中选择一组初始对象并显示在列表中,然后可以选择列表中的项目进行编辑。当编辑器出现时,它具有类中许多数据字段的表单字段。
我遇到的问题是,我必须创建一个控制器,将每个数据元素映射到正确的表单元素,并创建大量的小型转换映射代码行,以将数字转换为字符串,并将正确的元素设置为下拉菜单,然后是另一个过多的代码,用于在单击保存按钮时返回并使用表单中的所有值更新基础对象。
我的问题是;有没有更直接的方法让表单的编辑直接修改我的类实例的内容?我希望能够有一个可以配置的默认映射“控制器”,然后根据需要覆盖特定字段的 getter/setter。理想情况下,会对电话号码、整数、浮点数、邮政编码等进行标准字段验证...
我并不反对自己编写此内容,我只是想看看它是否已经存在并使用正确的工具适合正确的工作。
I started using netbeans to design forms to edit the instances of various classes I have made in a small app I am writing. Basically, the app starts, an initial set of objects is selected from the DB and presented in a list, then an item in the list can be selected for editing. When the editor comes up it has form fields for many of the data fields in the class.
The problem I run into is that I have to create a controller that maps each of the data elements to the correct form element, and create an inordinate number of small conversion mapping lines of code to convert numbers into strings and set the correct element in a dropdown, then another inordinate amount of code to go back and update the underlying object with all the values from the form when the save button is clicked.
My question is; is there a more directly way to make the editing of the form directly modify the contents of my class instance? I would like to be able to have a default mapping "controller" that I can configure, then override the getter/setter for a particular field if needed. Ideally, there would be standard field validation for things like phone numbers, integers, floats, zip codes, etc...
I'm not averse to writing this myself, I would just like to see if it is already out there and use the right tool for the right job.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有很多方法,
例如,JBoss Seam 使用 Ant(无论您是否知道,NetBeans 使用Ant 在幕后)名为 hbmtemplate 的工具。它是一个基于模板的引擎,可以由用户提供的模板或类进行控制。它与 Freemarker 模板(.flt 扩展名)一起生成所有应用程序。如果您想了解 Seam 如何生成其应用程序,请查看/seam-gen/view。在那里,你可以看到很多 Freemarker 模板。
下面是 Seam 生成其应用程序的方式
这里是来自 FreeMarket 模板 view.xhtml.ftl 的一些代码,不是全部,
我希望它对您有用
There are many approaches,
JBoss Seam, for instance, uses an Ant (And whether you do not know, NetBeans uses Ant behind the scenes) tool called hbmtemplate. It is a Template based Engine in which can be controlled by a user provided template or class. Along with Freemarker Template (.flt extension), it generates all of Application. If you want to see how see how Seam generates its Applications, Take a look at <SEAM_HOME>/seam-gen/view. There, you can see o lot of Freemarker Template.
Here is how Seam generates its Application
Here goes some code, not all, from FreeMarket Template view.xhtml.ftl
I hope it can be useful to you
请参阅我对您的其他问题的回答 这里。 (简而言之:我希望使用 beans 绑定会有所帮助)
See my answer to your other question here. (In short: using beans binding would help a bit I hope)