2010-03-23 6 views
1

필자가 작성한 작은 응용 프로그램에서 만든 다양한 클래스의 인스턴스를 편집하기 위해 netbeans를 사용하여 양식을 디자인하기 시작했습니다. 기본적으로 앱이 시작되고 DB에서 개체의 초기 집합이 선택되어 목록에 표시되면 목록의 항목을 편집하도록 선택할 수 있습니다. 편집기가 나타나면 클래스의 많은 데이터 필드에 대한 양식 필드가 있습니다.JPA POJO 클래스 + Netbeans 양식을 함께 사용하려면 어떻게해야합니까?

문제는 각 데이터 요소를 올바른 양식 요소에 매핑하고 작은 변환 매핑 코드 줄을 과도하게 생성하여 숫자를 문자열로 변환하고 드롭 다운에서 올바른 요소를 누른 다음 다시 돌아가서 저장 버튼을 클릭 할 때 폼의 모든 값으로 기본 객체를 업데이트하는 또 다른 과도한 양의 코드.

내 질문은; 폼의 편집을 직접적으로 내 클래스 인스턴스의 내용을 수정하는 더 직접적인 방법은 무엇입니까? 내가 구성 할 수있는 기본 매핑 "컨트롤러"를 가질 수있게하고 싶습니다. 그리고 필요한 경우 특정 필드에 대한 getter/setter를 재정의합니다. 이상적으로는 전화 번호, 정수, 수레, 우편 번호 등과 같은 것들에 대한 표준 필드 유효성 검사가 있습니다.

저는이 글을 쓰는 것에 싫어합니다. 이미 글을 쓰고 싶습니다. 적절한 작업에 적합한 도구를 사용하십시오.

JBoss Seam 많은 방법이있다

답변

1

다른 질문에 대한 대답을 참조하십시오 here. (간단히 말해서, 빈 바인딩을 사용하면 약간의 도움이 될 것입니다.)

2

는, 예를 들어, Ant를 사용하는 (그리고 당신이 모르는 여부, NetBeans는 무대 뒤에서 Ant를 사용) hbmtemplate라는 도구입니다. 이것은 사용자가 제공 한 템플릿이나 클래스에 의해 제어 될 수있는 템플릿 기반 엔진입니다. Freemarker 템플릿 (.flt 확장자)과 함께 모든 응용 프로그램을 생성합니다. Seam이 애플리케이션을 생성하는 방법을 확인하려면 <SEAM_HOME>/seam-gen/view를 확인하십시오. Freemarker 템플릿을 많이 볼 수 있습니다. 여기

는 Seam이

<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> 

가 여기에 내가 그에게 도움이 될 수 있기를 바랍니다

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

view.xhtml.ftl 자유 시장 템플릿에서, 모든 일부 코드를 간다 자사의 응용 프로그램을 생성하는 방법입니다 당신

관련 문제